[Numpy-discussion] Accessing elements of an object array

lists_ravi@lavabi... lists_ravi@lavabi...
Wed Mar 16 15:18:03 CDT 2011

  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
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.


More information about the NumPy-Discussion mailing list