[Numpy-discussion] problem with assigning to recarrays
Fri Feb 27 19:06:33 CST 2009
On Feb 27, 2009, at 4:30 PM, Robert Kern wrote:
> r[where(r.field1 == 1.)] make a copy. There is no way for us to
> construct a view onto the original memory for this circumstance given
> numpy's memory model.
Many thanks for the quick reply. I assume that this is true only for
record arrays, not for ordinary arrays? Certainly I can make an
assignment in this way with a normal array.
Also, if it is truly impossible to change this behavior, or to have it
raise an error--then are there any best-practice suggestions for how
to remember and avoid running into this non-obvious behavior? If one
thinks of record arrays as inheriting from numpy arrays, then this
problem is certainly unexpected.
Also, I've just found that the following syntax does do what is
(r.field2)[where(field1 == 1.)] = 1.
It is at least a little aesthetically displeasing that the syntax
works one way but not the other. Perhaps my best bet is to stick with
this syntax and forget that the other exists? A less-than-satisfying
solution, but workable.
> r[where(r.field1 == 1.)].field2 = 0.0 assigns to the copy.
> Robert Kern
> "I have come to believe that the whole world is an enigma, a harmless
> enigma that is made terrible by our own mad attempt to interpret it as
> though it had an underlying truth."
> -- Umberto Eco
> Numpy-discussion mailing list
More information about the Numpy-discussion