[SciPy-User] masked recarray, recarray with one field of type "ndarray"
Wed Feb 1 10:36:38 CST 2012
Thanks for the help! Now is there any way to mask elements of a
recarray? I should explain the application because I think I may be
going about this the wrong way:
I'll be building a tree and each node will have some attributes (for
example, a matrix). I often have to iterate through every node of the
tree and do a calculation -- something that I could do in a vectorized
way with NumPy if all the attributes were stored in an array. So I
thought I could represent the tree as a recarray (that I'd
occasionally need to grow).
I'd also need to delete nodes from the tree occasionally. I'd
accomplish this by masking entries of the recarray. When I needed to
add a node to the tree, I'd try to populate a masked entry before
going to the end of the array.
On Tue, Jan 31, 2012 at 9:33 AM, Warren Weckesser
> On Tue, Jan 31, 2012 at 2:36 AM, Gustavo Goretkin
> <email@example.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
> Here's how it can be done with the dtype argument (in this case, the
> "sub-arrays" are 3x5 float32):
> In : dt = np.dtype([('id', int32), ('values', float32, (3,5))])
> In : a = np.recarray(shape=(3,), dtype=dt)
> In : a.id
> Out: array([ 7, 2345536, 8585218])
> In : a.id
> Out: 7
> In : a.values
> 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 : a.values.shape
> Out: (3, 5)
> SciPy-User mailing list
More information about the SciPy-User