Mercurial > pylearn
comparison dataset.py @ 8:d1c394486037
Replaced asarray() method by __array__ method which gets called automatically when
trying to cast into an array or numpy array or upon numpy.asarray(dataset).
author | bengioy@bengiomac.local |
---|---|
date | Mon, 24 Mar 2008 15:56:53 -0400 |
parents | 6f8f338686db |
children | de616c423dbd |
comparison
equal
deleted
inserted
replaced
7:6f8f338686db | 8:d1c394486037 |
---|---|
105 A fixed-length and fixed-width dataset in which each element is a numpy array | 105 A fixed-length and fixed-width dataset in which each element is a numpy array |
106 or a number, hence the whole dataset corresponds to a numpy array. Fields | 106 or a number, hence the whole dataset corresponds to a numpy array. Fields |
107 must correspond to a slice of columns. If the dataset has fields, | 107 must correspond to a slice of columns. If the dataset has fields, |
108 each 'example' is just a one-row ArrayDataSet, otherwise it is a numpy array. | 108 each 'example' is just a one-row ArrayDataSet, otherwise it is a numpy array. |
109 Any dataset can also be converted to a numpy array (losing the notion of fields) | 109 Any dataset can also be converted to a numpy array (losing the notion of fields) |
110 by the asarray(dataset) call. | 110 by the numpy.array(dataset) call. |
111 """ | 111 """ |
112 | 112 |
113 def __init__(self,dataset=None,data=None,fields={},minibatch_size=1): | 113 def __init__(self,dataset=None,data=None,fields={},minibatch_size=1): |
114 """ | 114 """ |
115 Construct an ArrayDataSet, either from a DataSet, or from | 115 Construct an ArrayDataSet, either from a DataSet, or from |
185 | 185 |
186 def __getslice__(self,*slice_args): | 186 def __getslice__(self,*slice_args): |
187 """dataset[i:j] returns the subdataset with examples i,i+1,...,j-1.""" | 187 """dataset[i:j] returns the subdataset with examples i,i+1,...,j-1.""" |
188 return ArrayDataSet(data=self.data[apply(slice,slice_args)],fields=self.fields) | 188 return ArrayDataSet(data=self.data[apply(slice,slice_args)],fields=self.fields) |
189 | 189 |
190 def asarray(self): | 190 def __array__(self): |
191 if not self.fields: | 191 if not self.fields: |
192 return self.data | 192 return self.data |
193 # else, select subsets of columns mapped by the fields | 193 # else, select subsets of columns mapped by the fields |
194 columns_used = numpy.zeros((self.data.shape[1]),dtype=bool) | 194 columns_used = numpy.zeros((self.data.shape[1]),dtype=bool) |
195 for field_slice in self.fields.values(): | 195 for field_slice in self.fields.values(): |