[Numpy-discussion] Using dtype=object

Nathan Faggian nathan.faggian at gmail.com
Tue Nov 15 00:08:45 EST 2011


Hi,

I am interested in the use of numpy with native python objects, like so:

In [91]: import collections
In [92]: testContainer = collections.namedtuple('testContainer', 'att1
att2 att3')
In [93]: test1 = testContainer(1, 2, 3)
In [94]: test2 = testContainer(4, 5, 6)
In [95]: test1
Out[95]: testContainer(att1=1, att2=2, att3=3)
In [96]: test2
Out[96]: testContainer(att1=4, att2=5, att3=6)
In [97]: x = np.empty((2,2), dtype=object)
In [98]: x[0,0] = test1
In [99]: x[1,1] = test2
In [100]: x
Out[100]:
array([[testContainer(att1=1, att2=2, att3=3), None],
       [None, testContainer(att1=4, att2=5, att3=6)]], dtype=object)

Does anyone know if it possible to form a mask using the attributes of
the objects stored in the ndarray?

After a few failed attempts I am left wondering if I should use a
prepared dtype instead.

Cheers,

Nathan.



More information about the NumPy-Discussion mailing list