[Numpy-discussion] mrecarray indexing behaviour

Joel Nothman jnothman at student.usyd.edu.au
Sun Apr 7 04:45:13 EDT 2013

Hello all!

I am a bit confused by the behaviour of mrecarray:

>>> import numpy.ma.mrecords
>>> data = [(1, 'a'), (2, 'b')]
>>> ra = numpy.rec.fromrecords(data)
>>> mra = numpy.ma.mrecords.fromrecords(data)
>>> ra
rec.array([(1, 'a'), (2, 'b')],
      dtype=[('f0', '<i4'), ('f1', '|S1')])
>>> mra
    f0 : [1 2]
    f1 : [a b]
    fill_value : (999999, 'N')
>>> for a in [ra, mra]:
...   for cname, cell in [('row first', a[0]['f1']), ('field first',
...     print(type(a), cname, cell, type(cell), sep=', ')
<class 'numpy.core.records.recarray'>, row first, a, <type 'numpy.string_'>
<class 'numpy.core.records.recarray'>, field first, a, <type
<class 'numpy.ma.mrecords.MaskedRecords'>, row first, a, <class
<class 'numpy.ma.mrecords.MaskedRecords'>, field first, a, <type

Why when I index an mrecarray by offset before field do I get a
zero-dimension MaskedArray instead of the object I get when indexing by
field then offset?

This seems strange behaviour. Is it documented?

It doesn't seem to be tested;
equality of value but says nothing about the types that should be
returned. Similarly:

>>> mra['f1'][0] == mra[0]['f1']
masked_array(data = True,
             mask = False,
       fill_value = True)

>>> type(mra['f1'][0]) == type(mra[0]['f1'])

I look forward to any explanation or clarification!


- Joel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130407/b965f6f9/attachment.html>

More information about the NumPy-Discussion mailing list