[Numpy-discussion] Accessing elements of an object array

lists_ravi at lavabit.com lists_ravi at lavabit.com
Wed Mar 16 16:18:03 EDT 2011


Hi,
  How do I access elements of an object array? The object array was
created by scipy.io.loadmat from a MAT file. Here's an example:

In [10]: x
Out[10]:
array(array((7.399500875785845e-10, 7.721153414752673e-10, -0.984375),
      dtype=[('cl', '|O8'), ('tl', '|O8'), ('dagc', '|O8')]), dtype=object)

In [11]: x.shape, x.size
Out[11]: ((), 1)

In [12]: x.flat[0]['cl']
Out[12]: array(array(7.399500875785845e-10), dtype=object)

In [13]: x[0]
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)

/src/<ipython console> in <module>()

IndexError: 0-d arrays can't be indexed



I am using numpy 1.4.1 on Linux x86_64, if that matters.

Regards,
Ravi






More information about the NumPy-Discussion mailing list