Re: [Numpy-discussion] [SciPy-dev] SciPy Sprint results

2007-12-21 Thread Stefan van der Walt
Hi Travis

On Thu, Dec 20, 2007 at 05:24:44PM -0600, Travis E. Oliphant wrote:
  * bool(x) raises a ValueError, as it does for ndarrays.

 What does bool(x) raise for numpy.core.ma.

It now behaves the same way as numpy does, raising a ValueError:

In [1]: bool(N.ma.array([0,1]))
---
ValueErrorTraceback (most recent call last)

/home/stefan/work/scipy/ipython console in module()

ValueError: The truth value of an array with more than one element is 
ambiguous. Use a.any() or a.all()

In [2]: bool(N.array([0,1]))
---
ValueErrorTraceback (most recent call last)

/home/stefan/work/scipy/ipython console in module()

ValueError: The truth value of an array with more than one element is 
ambiguous. Use a.any() or a.all()

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


Re: [Numpy-discussion] [SciPy-dev] SciPy Sprint results

2007-12-21 Thread Stefan van der Walt
On Fri, Dec 21, 2007 at 10:43:28AM +0200, Stefan van der Walt wrote:
 On Thu, Dec 20, 2007 at 05:24:44PM -0600, Travis E. Oliphant wrote:
   * bool(x) raises a ValueError, as it does for ndarrays.
 
  What does bool(x) raise for numpy.core.ma.

Sorry, I realise you were talking about the old numpy.core.ma:

z = N.core.ma.masked_array([True,False,True])
bool(z) == True

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


Re: [Numpy-discussion] [SciPy-dev] SciPy Sprint results

2007-12-21 Thread Stefan van der Walt
On Thu, Dec 20, 2007 at 06:52:38PM -0500, Pierre GM wrote:
  If we can document exactly what the compatibility issues are (and it
  looks like we are almost there), we should move forward.
 
 OK, I'll take care of that this week-end. Stefan, feel free to beat me to 
 it...

A first draft is here:

http://svn.scipy.org/svn/numpy/branches/maskedarray/numpy/ma/API_CHANGES.txt

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


Re: [Numpy-discussion] [SciPy-dev] SciPy Sprint results

2007-12-21 Thread Eric Firing
Stefan,

I think the description of the putmask difference is missing the point. 
  The real difference is not in the way the third argument is handled, 
or  its required shape, but in whether the mask is updated or not.

numpy.ma.putmask updates the mask; that is, if it puts something into 
the array in a formerly masked location, the mask at that location is 
changed to False.

maskedarray.putmask does *not* update the original mask; it does a 
ndarray putmask operation on only the *unmasked* values.


In [18]:import maskedarray as ma
In [19]:mask1 = [False, True, False]
In [21]:x = ma.array([1,2,3], mask=mask1)
In [22]:mask2 = [False, True, True]
In [23]:ma.putmask(x, mask2, 10)
In [24]:x
Out[24]:
masked_array(data = [1 -- 10],
   mask = [False  True False],
   fill_value=99)

In [25]:x = numpy.ma.array([1,2,3], mask=mask1)
In [26]:numpy.ma.putmask(x, mask2, 10)
In [27]:x
Out[27]:
array(data =
  [ 1 10 10],
   mask =
  [False False False],
   fill_value=99)


This is a fundamental difference.  The maskedarray (new) behavior 
perhaps is more consistent with the general pattern of differences 
between masked and unmasked array functions and methods.

Eric

Stefan van der Walt wrote:
 On Thu, Dec 20, 2007 at 06:52:38PM -0500, Pierre GM wrote:
 If we can document exactly what the compatibility issues are (and it
 looks like we are almost there), we should move forward.
 OK, I'll take care of that this week-end. Stefan, feel free to beat me to 
 it...
 
 A first draft is here:
 
 http://svn.scipy.org/svn/numpy/branches/maskedarray/numpy/ma/API_CHANGES.txt
 
 Regards
 Stéfan
 ___
 Numpy-discussion mailing list
 Numpy-discussion@scipy.org
 http://projects.scipy.org/mailman/listinfo/numpy-discussion

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


Re: [Numpy-discussion] [SciPy-dev] SciPy Sprint results

2007-12-20 Thread Travis E. Oliphant
Stefan van der Walt wrote:
 Hi Travis,

 During the sprint I also merged Pierre's MaskedArray code into the
 maskedarray branch.  That is nearly done, with only a few unit tests
 still failing -- ones brought over from the old numpy.ma.

 This is mainly due to some changes in the API, for example put and
 putmask now behave like their ndarray counterparts.  Pierre, would you
 remind us of any other such changes, and why they were made?

 What is the road forward with this code?  We will probably only merge
 API changes into 1.4.  Do we use svnmerge to keep the branch up to
 date until then?
   

I'd like to move forward with it sooner (for 1.0.5) if the API changes 
are not drastic.  Although ideally 0 API changes would be desireable, 
I'm not sure if that is feasible.   Are put and putmask the only changes 
in the API.  What are the rest of them?

-Travis

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


Re: [Numpy-discussion] [SciPy-dev] SciPy Sprint results

2007-12-20 Thread Travis E. Oliphant
Pierre GM wrote:
 All,

   
 I'd like to move forward with it sooner (for 1.0.5) if the API changes
 are not drastic.  Although ideally 0 API changes would be desireable,
 I'm not sure if that is feasible.   Are put and putmask the only changes
 in the API.  What are the rest of them?
 

   
These do not seem too bad.
 * put, putmask, take should behave like the numpy equivalent.
   
This does not sound like a problem.  Am I missing something?
 * fill_value is now a property, not a method.
   
I can see this is a good choice, but it is a backward compatibility 
issue that we should document.
 * cumsum(cumprod) works as if the _data array was filled with 0 (1). The mask 
 is preserved, but not updated. (the output of numpy.core.ma has nomask).
   
I don't understand what you mean here.So, the mask effectively 
removes those elements from the sum(product) computation?  What does it 
mean that the mask is not updated?
 * bool(x) raises a ValueError, as it does for ndarrays.
   
What does bool(x) raise for numpy.core.ma.

If we can document exactly what the compatibility issues are (and it 
looks like we are almost there), we should move forward.

-Travis
 

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


Re: [Numpy-discussion] [SciPy-dev] SciPy Sprint results

2007-12-20 Thread Pierre GM
  * cumsum(cumprod) works as if the _data array was filled with 0 (1). The
  mask is preserved, but not updated. (the output of numpy.core.ma has
  nomask).

 I don't understand what you mean here.So, the mask effectively
 removes those elements from the sum(product) computation?  What does it
 mean that the mask is not updated?

Quick example:
 x= masked_array([1,2,3],mask=[0,1,0])
 x
masked_array(data = [1 -- 3],
  mask = [False  True False],
  fill_value=99)
 x.cumsum()
masked_array(data = [1 -- 4],
  mask = [False  True False],
  fill_value=99)

So, cumsum works as if the masked values were 0. The mask stays the same as it 
was initially (that's what I meant by mask not updated).  An alternative 
would be to set the mask to True for all the values past the first masked: 
with our example, we would have:
masked_array(data = [1 --  --],
  mask = [False  True True],
  fill_value=99)
I prefer the first version (the one that is currently implemented).




  * bool(x) raises a ValueError, as it does for ndarrays.

 What does bool(x) raise for numpy.core.ma.

True

 If we can document exactly what the compatibility issues are (and it
 looks like we are almost there), we should move forward.

OK, I'll take care of that this week-end. Stefan, feel free to beat me to 
it...
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion