[SciPy-user] Masked arrays with dtype=object: elements get wrapped in 0D arrays
pgmdevlist at gmail.com
Tue Jan 9 11:22:12 CST 2007
> Is this a bug, or am I understanding something wrong?
Not really. Well, I don't know whether it should be a bug or not.
When you set an element `i` of masked array `a` to a value `val`, you actually
call the function "filled" on the value to set the `_data` part of `a`. This
function returns a numpy.array no matter what: `numpy.array(val)`. So, when
you actually have
a = numpy.array(0)
Which explains what you see.
If `a` has a classic dtype such as int_, float_..., `numpy.array(val)` is
transformed into a single element (int_, float_...), to fit the memory size
reserved for an array cell.
In your case, `a` is a object_ array: there's no transformation, as the memory
size of an object_ array cell can be modified.
Now, should 'filled' always return a numpy.array ? That's the case where we
wouldn't want this conversion, and an extra test could be added in `filled`,
along the lines of:
if isinstance(val,int) or isinstance(val,float) or isisinstance(val,complex)
That extra test will be costly in the long run: 'filled' is called quite often
At the same time, we could just return `val` no matter what (as long it's not
a masked array). I gonna try to check whether it breaks anything.
In the meanwhile: what are you trying to do ? There should be some kind of
More information about the SciPy-user