|
From: John H. <jd...@gm...> - 2007-03-02 19:12:28
|
On 3/2/07, Christopher Barker <Chr...@no...> wrote: > This sounds like EXACTLY the type of object that the array interface is > supposed to support. So what you need to do is give your object an array > interface: > > http://numpy.scipy.org/array_interface.shtml I still am not able to make my mock-up custom python class work as I would like with asarray (though it works with "list"). What am I missing? The way I read it this appears to be in support of extension code that wants to expose the array interface, but I have a python object that acts like a sequence (am I missing some important method) that wants to work properly with numpy.asarray class C: def __init__(self): self._data = (1,2,3,4,5) def __iter__(self): for i in self._data: yield i return def __getitem__(self, i): return self._data[i] def __getslice__(self, i, j): return self._data[i:j] def __len__(self): return len(self._data) def __array_interface__(self): return dict( shape=(len(self._data),), typestr='f', version=3) import numpy c = C() print numpy.asarray(c) #for i in c: # print i |