[SciPy-user] NaN's in numpy (and Scipy)
Pierre GM
pgmdevlist at gmail.com
Sat Jan 6 18:56:56 CST 2007
On Saturday 06 January 2007 19:22, Alan Jackson wrote:
> Well for one it seems a shame to carry around the extra storage when 99.9%
> of my data is not missing.
Booleans aren't that large.
> With normal arrays this could be done with
> b = concatenate((a[1:]-a[:-1],[a[-1]-a[-2]] )) or something close to that,
> I'm writing from memory. With masked arrays, you seem to lose the
> 'maskedness' when they are only one-d, so the concatenate fails and you
> have to fiddle about a bit to get it to work right. In my mind, it should
> "just work", so that the code looks the same in either case, but I couldn't
> get it to do that.
Are you sure you use the concatenate function from numpy.core.ma ?
And not the one from numpy ?
Because if you do use the one from numpy, you get a warning that the data is
masked in one or more location, and you end up with a basic ndarray, True. In
the new implementation, you raise an exception (not an helpful one, but I
can't control that)
>>>import numpy as N
>>>import numpy.core.ma as ma
>>>x = ma.array([1,2,3], mask=[0,0,1])
>>>print ma.concatenate([x,x])
[1 2 -- 1 2 --]
>>>N.concatenate([x,x])
[1 2 3 1 2 3]
Now, with the new implementation
>>>import maskedarray as MA\
>>>x=MA.array([1,2,3], mask=[0,0,1])
>>>print MA.concatenate([x,x])
[1 2 -- 1 2 --]
>>>N.concatenate([x,x])
AttributeError: 'NoneType' object has no attribute 'shape'
More information about the SciPy-user
mailing list