[Numpy-discussion] MA bug or feature? (original) (raw)
Michael Sorich michael.sorich at gmail.com
Wed Jun 21 22:01:59 EDT 2006
- Previous message (by thread): [Numpy-discussion] MA bug or feature?
- Next message (by thread): [Numpy-discussion] MA bug or feature?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I was setting the fill_value as 'NA' when constructing the array so the masked values would be printed as 'NA'. It is not a big deal to avoid doing this.
Nevertheless, the differences between a masked array with a boolean mask and a mask of booleans have caused me trouble before. Especially when there are hidden in-place conversions of a mask which is a array of False to a mask which is False. e.g.
import numpy print numpy.version.version
ma1 = numpy.ma.array(((1.,2,3),(4,5,6)), mask=((0,0,0),(0,0,0))) print ma1.mask a1 = numpy.asarray(ma1) print ma1.mask
0.9.9.2538 [[False False False] [False False False]] False
On 6/21/06, Pierre GM <pgmdevlist at mailcan.com> wrote:
On Wednesday 21 June 2006 04:46, Michael Sorich wrote: > When transposing a masked array of dtype '<f8' I noticed that an_ _> ndarray of dtype '|O4' was returned.
OK, I see where the problem is: When your fillvalue has a type that cannot be converted to the type of your data, the
filled
method (used internally in many functions, such astranspose
) raises a TypeError, which is caught and your array is converted to 'O'. That's what happen here: your fillvalue is a string, your data are integer, the types don't match, hence the conversion. So, no, I don't think that's a bug. Why filling when you don't have any masked values, then ? Well, there's a subtle difference between a boolean mask and a mask of booleans. When the mask is boolean (mask=nomask=False), there's no masked value, andfilled
returns the data. Now, when your mask is an array of boolean (your first case), MA doesn't check whether mask.any()==False to determine whether there are some missing data or not, it just processes the whole array of boolean. I agree that's a bit confusing here, and there might be some room for improvement (for example, changing the currentif m is nomask
toif m is nomask or m.any()==False
, or better, forcing mask to nomask if mask.any()==False). But I don;t think that qualifies as bug. In short: when you have an array of numbers, don't try to fill it with characters.
- Previous message (by thread): [Numpy-discussion] MA bug or feature?
- Next message (by thread): [Numpy-discussion] MA bug or feature?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]