[SciPy-user] sequence emulation -/-> array access?

Alan G Isaac aisaac at american.edu
Sat Dec 17 14:47:36 CST 2005


> On Fri, Dec 16, 2005 at 10:40:55AM -0500, Alan G Isaac wrote: 
>> Is a special array interface necessary for scipy.array 
>> to access even simple sequence emulators? 
>> E.g., suppose I have 
>> >>> class simple: 
>> ...  def __init__(self,data): 
>> ...   self.data = data 
>> ... 
>> where it is enforced that data is a list, 
>> and to class this I add sequence emulation 
>> http://docs.python.org/ref/sequence-types.html 

>> Can someone please point me to a minimal example where 
>> I can then do
>> x = simple([1,2,3])
>> y = scipy.array(x)
>> and end up with an array of the list values
>> (just like when you do scipy.array([1,2,3])). 



On Fri, 16 Dec 2005, Dave Kuhlman apparently wrote: 
>     # This should work OK.  # def test1(): x = Simple([1., 
>     2., 3.,]) y = scipy.array(x.get_data()) print y 



Sure.  But I want to be able to do
x = simple([1,2,3])
y = scipy.array(x)
One reason: I don't want to test for what
kind of object I am passing to scipy.array,
whether it has the get_data attribute, etc.

So my question is:
what is a minimal set of attributes to allow
this to work.  I have found that sequence emulation (see:
http://docs.python.org/ref/sequence-types.html )
is not enough.

Cheers,
Alan Isaac






More information about the SciPy-user mailing list