[Numpy-discussion] a view of a numpy object array

YW yichun.wei at gmail.com
Wed Jan 30 04:56:32 EST 2008


Hi,

How would one deal with the problem of getting a view of a numpy
object array? For example,

In [49]: b
Out[49]:
TaskResultArray([[TaskResult[ID:0]:{'out': 22}, TaskResult[ID:1]:
{'out': 22},
        TaskResult[ID:2]:{'out': 16}, TaskResult[ID:3]:{'out': 16},
        TaskResult[ID:4]:{'out': 16}],
       [TaskResult[ID:5]:{'out': 16}, None, None, None, None],
       [None, None, None, None, None],
       [None, None, None, None, None],
       [None, None, None, None, None]], dtype=object)

In [50]: b.shape
Out[50]: (5, 5)

In [58]: b[0,0]['out']
Out[58]: 21

What would be the best way without looping and copying, to get a view
of this array, say c, so that we have

In [69]: c
Out[69]:
array([[ 21.,  22.,  16.,  16.,  16.],
       [ 16.,  NaN,  NaN,  NaN,  NaN],
       [ NaN,  NaN,  NaN,  NaN,  NaN],
       [ NaN,  NaN,  NaN,  NaN,  NaN],
       [ NaN,  NaN,  NaN,  NaN,  NaN]])

it is desired that c is a view instead of a copy so no extra care of
updating c is needed. Is the tools that does this available in current
numpy already?

thanks in advance




More information about the NumPy-Discussion mailing list