[SciPy-User] masked recarray, recarray with one field of type "ndarray"

Warren Weckesser warren.weckesser@enthought....
Tue Jan 31 08:33:48 CST 2012


On Tue, Jan 31, 2012 at 2:36 AM, Gustavo Goretkin <
gustavo.goretkin@gmail.com> wrote:

> Does a recarray support masking?
>
> Can I have a recarray where one of the fields is an M-by-N ndarray
> (not recarray) of some dtype?
> ex: a = np.recarray(shape=(10),formats=['i4','f8','3-by-3 ndarray of
> dtype=float64'])
>


Here's how it can be done with the dtype argument (in this case, the
"sub-arrays" are 3x5 float32):

In [21]: dt = np.dtype([('id', int32), ('values', float32, (3,5))])

In [22]: a = np.recarray(shape=(3,), dtype=dt)

In [23]: a.id
Out[23]: array([      7, 2345536, 8585218])

In [24]: a[0].id
Out[24]: 7

In [25]: a[0].values
Out[25]:
array([[  9.80908925e-45,   2.15997513e-37,   3.16079124e-39,
          1.18408375e-38,   2.81552923e-38],
       [  2.13004362e-37,  -7.69011974e-02,   9.80908925e-45,
          9.80908925e-45,   3.62636667e-21],
       [  5.67059093e-24,   5.67095065e-24,   5.64768872e-24,
          7.86448908e+11,   0.00000000e+00]], dtype=float32)

In [26]: a[0].values.shape
Out[26]: (3, 5)


Warren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20120131/bc2f33e1/attachment.html 


More information about the SciPy-User mailing list