Re: [Numpy-discussion] Unexpected MaskedArray behavior

2008-12-17 Thread Jim Vickroy

Ryan May wrote:

Pierre GM wrote:
  

On Dec 16, 2008, at 1:57 PM, Ryan May wrote:


I just noticed the following and I was kind of surprised:

  

a = ma.MaskedArray([1,2,3,4,5], mask=[False,True,True,False,False])
b = a*5
b


masked_array(data = [5 -- -- 20 25],
  mask = [False  True  True False False],
  fill_value=99)
  

b.data


array([ 5, 10, 15, 20, 25])

I was expecting that the underlying data wouldn't get modified while  
masked.  Is

this actual behavior expected?
  
Meh. Masked data shouldn't be trusted anyway, so I guess it doesn't  
really matter one way or the other.
But I tend to agree, it'd make more sense leave masked data untouched  
(or at least, reset them to their original value after the operation),  
which would mimic the behavior of gimp/photoshop.
Looks like there's a relatively easy fix. I need time to check whether  
it doesn't break anything elsewhere, nor that it slows things down too  
much. I won't have time to test all that before next week, though. In  
any case, that would be for 1.3.x, not for 1.2.x.

In the meantime, if you need the functionality, use something like
ma.where(a.mask,a,a*5)



I agree that masked values probably shouldn't be trusted, I was just surprised to 
see the behavior.  I just assumed that no operations were taking place on masked 
values.


Just to clarify what I was doing here: I had a masked array of data, where the 
mask was set by a variety of different masked values.  Later on in the code, 
after doing some unit conversions, I went back to look at the raw data to find 
points that had one particular masked value set.  Instead, I was surprised to see 
all of the masked values had changed and I could no longer find any of the 
special values in the data.


Ryan

  
Sorry for being dense about this, but I really do not understand why 
masked values should not be trusted.  If I apply a procedure to an array 
with elements designated as untouchable, I would expect that contract to 
be honored.  What am I missing here?


Thanks for your patience!
-- jv
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Unexpected MaskedArray behavior

2008-12-17 Thread Pierre GM

On Dec 17, 2008, at 12:13 PM, Jim Vickroy wrote:

 Sorry for being dense about this, but I really do not understand why  
 masked values should not be trusted.  If I apply a procedure to an  
 array with elements designated as untouchable, I would expect that  
 contract to be honored.  What am I missing here?

 Thanks for your patience!
 -- jv

Everything depends on your interpretation of masked data.  
Traditionally, masked data indicate invalid data, whatever the cause  
of the invalidity. Operations involving invalid data yield invalid  
data, hence the presence of a mask on the result. However, the value  
underneath the mask is still invalid, hence the statement don't trust  
masked values.
Interpreting a mask as a way to prevent some elements of an array to  
be processed (designating them as untouchable) is a bit of a stretch.  
Nevertheless, I agree that this behavior is not intuitive, so I'll  
check what I can do.


___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Unexpected MaskedArray behavior

2008-12-17 Thread Ryan May
Pierre GM wrote:
 On Dec 16, 2008, at 1:57 PM, Ryan May wrote:
 I just noticed the following and I was kind of surprised:

 a = ma.MaskedArray([1,2,3,4,5], mask=[False,True,True,False,False])
 b = a*5
 b
 masked_array(data = [5 -- -- 20 25],
   mask = [False  True  True False False],
   fill_value=99)
 b.data
 array([ 5, 10, 15, 20, 25])

 I was expecting that the underlying data wouldn't get modified while  
 masked.  Is
 this actual behavior expected?
 
 Meh. Masked data shouldn't be trusted anyway, so I guess it doesn't  
 really matter one way or the other.
 But I tend to agree, it'd make more sense leave masked data untouched  
 (or at least, reset them to their original value after the operation),  
 which would mimic the behavior of gimp/photoshop.
 Looks like there's a relatively easy fix. I need time to check whether  
 it doesn't break anything elsewhere, nor that it slows things down too  
 much. I won't have time to test all that before next week, though. In  
 any case, that would be for 1.3.x, not for 1.2.x.
 In the meantime, if you need the functionality, use something like
 ma.where(a.mask,a,a*5)

I agree that masked values probably shouldn't be trusted, I was just surprised 
to 
see the behavior.  I just assumed that no operations were taking place on 
masked 
values.

Just to clarify what I was doing here: I had a masked array of data, where the 
mask was set by a variety of different masked values.  Later on in the code, 
after doing some unit conversions, I went back to look at the raw data to find 
points that had one particular masked value set.  Instead, I was surprised to 
see 
all of the masked values had changed and I could no longer find any of the 
special values in the data.

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Unexpected MaskedArray behavior

2008-12-16 Thread Ryan May
Hi,

I just noticed the following and I was kind of surprised:

 a = ma.MaskedArray([1,2,3,4,5], mask=[False,True,True,False,False])
 b = a*5
  b
masked_array(data = [5 -- -- 20 25],
   mask = [False  True  True False False],
   fill_value=99)
  b.data
array([ 5, 10, 15, 20, 25])

I was expecting that the underlying data wouldn't get modified while masked.  
Is 
this actual behavior expected?

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Unexpected MaskedArray behavior

2008-12-16 Thread Pierre GM

On Dec 16, 2008, at 1:57 PM, Ryan May wrote:

 I just noticed the following and I was kind of surprised:

 a = ma.MaskedArray([1,2,3,4,5], mask=[False,True,True,False,False])
 b = a*5
 b
 masked_array(data = [5 -- -- 20 25],
   mask = [False  True  True False False],
   fill_value=99)
 b.data
 array([ 5, 10, 15, 20, 25])

 I was expecting that the underlying data wouldn't get modified while  
 masked.  Is
 this actual behavior expected?

Meh. Masked data shouldn't be trusted anyway, so I guess it doesn't  
really matter one way or the other.
But I tend to agree, it'd make more sense leave masked data untouched  
(or at least, reset them to their original value after the operation),  
which would mimic the behavior of gimp/photoshop.
Looks like there's a relatively easy fix. I need time to check whether  
it doesn't break anything elsewhere, nor that it slows things down too  
much. I won't have time to test all that before next week, though. In  
any case, that would be for 1.3.x, not for 1.2.x.
In the meantime, if you need the functionality, use something like
ma.where(a.mask,a,a*5)

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion