comparison dataset.py @ 15:88168361a5ab

comment re: ArrayDataSet.__array__
author bergstrj@iro.umontreal.ca
date Tue, 25 Mar 2008 13:38:51 -0400
parents de616c423dbd
children 813723310d75
comparison
equal deleted inserted replaced
10:80bf5492e571 15:88168361a5ab
189 def __getslice__(self,*slice_args): 189 def __getslice__(self,*slice_args):
190 """dataset[i:j] returns the subdataset with examples i,i+1,...,j-1.""" 190 """dataset[i:j] returns the subdataset with examples i,i+1,...,j-1."""
191 return ArrayDataSet(data=self.data[apply(slice,slice_args)],fields=self.fields) 191 return ArrayDataSet(data=self.data[apply(slice,slice_args)],fields=self.fields)
192 192
193 def __array__(self): 193 def __array__(self):
194 """Return an view of this dataset which is an numpy.ndarray
195
196 Numpy uses this special function name to retrieve an ndarray view for
197 function such as numpy.sum, numpy.dot, numpy.asarray, etc.
198
199 If this dataset has no fields, then we simply return self.data,
200 otherwise things are complicated.
201 - why do we want this behaviour when there are fields? (JB)
202 """
194 if not self.fields: 203 if not self.fields:
195 return self.data 204 return self.data
196 # else, select subsets of columns mapped by the fields 205 # else, select subsets of columns mapped by the fields
197 columns_used = numpy.zeros((self.data.shape[1]),dtype=bool) 206 columns_used = numpy.zeros((self.data.shape[1]),dtype=bool)
198 for field_slice in self.fields.values(): 207 for field_slice in self.fields.values():