[SciPy-dev] object array question

Jeff Whitaker jswhit at fastmail.fm
Thu Dec 22 18:19:16 CST 2005


Hi:  The following script:

import scipy.base as SP
al = []
for j in range(10):
    al.append(SP.arange(j+1))
a = SP.array(al,'O')
print a
print a[5][:]

crashes at the last line (using scipy_core 0.8.4) when trying to access 
the object array.

[mac28:~/python/netcdf4] jsw% python test_objectarr_sp.py
[array([0]), array([0, 1]), array([0, 1, 2]), array([0, 1, 2, 3]), 
array([0, 1, 2, 3, 4]), array([0, 1, 2, 3, 4, 5]), array([0, 1, 2, 3, 4, 
5, 6]), array([0, 1, 2, 3, 4, 5, 6, 7]), array([0, 1, 2, 3, 4, 5, 6, 7, 
8]), array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])]
Traceback (most recent call last):
  File "test_objectarr_sp.py", line 9, in ?
    print a[5][:]
ValueError: 0-d arrays can't be indexed.


In numarray, this worked:

import numarray.objects as SP
al = []
for j in range(10):
    al.append(SP.arange(j+1))
a = SP.array(al,typecode='O')
print a
print a[5][:]


[mac28:~/python/netcdf4] jsw% python test_objectarr_sp.py
[array([0]) array([0, 1]) array([0, 1, 2]) array([0, 1, 2, 3])
 array([0, 1, 2, 3, 4]) array([0, 1, 2, 3, 4, 5])
 array([0, 1, 2, 3, 4, 5, 6]) array([0, 1, 2, 3, 4, 5, 6, 7])
 array([0, 1, 2, 3, 4, 5, 6, 7, 8])
 array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])]
[0 1 2 3 4 5]


Any idea why scipy_core behaves this way?  How do you access the data in 
objects stored in a object array?

-Jeff

-- 
Jeffrey S. Whitaker         Phone  : (303)497-6313
Meteorologist               FAX    : (303)497-6449
NOAA/OAR/PSD  R/PSD1        Email  : Jeffrey.S.Whitaker at noaa.gov
325 Broadway                Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web    : http://tinyurl.com/5telg




More information about the Scipy-dev mailing list