Re: [Numpy-discussion] read-only or immutable masked array

2013-07-15 Thread Gregorio Bastardo
Hi Pierre, I'm a bit surprised, though. Here's what I tried np.version.version 1.7.0 x = np.ma.array([1,2,3], mask=[0,1,0]) x.flags.writeable=False x[0]=-1 ValueError: assignment destination is read-only Thanks, it works perfectly =) Sorry, probably have overlooked this simple

Re: [Numpy-discussion] read-only or immutable masked array

2013-07-15 Thread Pierre Gerard-Marchant
On Jul 15, 2013, at 10:04 , Gregorio Bastardo gregorio.basta...@gmail.com wrote: Hi Pierre, I'm a bit surprised, though. Here's what I tried np.version.version 1.7.0 x = np.ma.array([1,2,3], mask=[0,1,0]) x.flags.writeable=False x[0]=-1 ValueError: assignment destination is

Re: [Numpy-discussion] read-only or immutable masked array

2013-07-15 Thread Gregorio Bastardo
Hi Pierre, Note as well that hardening the mask only prevents unmasking: you can still grow the mask, which may not be what you want. Use `x.mask.flags.writeable=False` to make the mask really read-only. I ran into an unmasking problem with the suggested approach: np.version.version

Re: [Numpy-discussion] Allow == and != to raise errors

2013-07-15 Thread bruno Piguet
Python itself doesn't raise an exception in such cases : (3,4) != (2, 3, 4) True (3,4) == (2, 3, 4) False Should numpy behave differently ? Bruno. 2013/7/12 Frédéric Bastien no...@nouiz.org I also don't like that idea, but I'm not able to come to a good reasoning like Benjamin. I

Re: [Numpy-discussion] empty_like for masked arrays

2013-07-15 Thread Gregorio Bastardo
Hi, On Mon, Jun 10, 2013 at 3:47 PM, Nathaniel Smith n...@pobox.com wrote: Hi all, Is there anyone out there using numpy masked arrays, who has an opinion on how empty_like (and its friends ones_like, zeros_like) should handle the mask? Right now apparently if you call np.ma.empty_like on

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Charles R Harris
On Sun, Jul 14, 2013 at 3:35 PM, Charles R Harris charlesr.har...@gmail.com wrote: On Sun, Jul 14, 2013 at 2:55 PM, Warren Weckesser warren.weckes...@gmail.com wrote: On 7/14/13, Charles R Harris charlesr.har...@gmail.com wrote: Some corner cases in the mean, var, std. *Empty

Re: [Numpy-discussion] Allow == and != to raise errors

2013-07-15 Thread Nathaniel Smith
On Mon, Jul 15, 2013 at 2:09 PM, bruno Piguet bruno.pig...@gmail.com wrote: Python itself doesn't raise an exception in such cases : (3,4) != (2, 3, 4) True (3,4) == (2, 3, 4) False Should numpy behave differently ? The numpy equivalent to Python's scalar == is called array_equal, and

Re: [Numpy-discussion] Allow == and != to raise errors

2013-07-15 Thread Sebastian Berg
On Mon, 2013-07-15 at 15:09 +0200, bruno Piguet wrote: Python itself doesn't raise an exception in such cases : (3,4) != (2, 3, 4) True (3,4) == (2, 3, 4) False Should numpy behave differently ? Yes, because Python tests whether the tuple is different, not whether the elements are:

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Benjamin Root
This is going to need to be heavily documented with doctests. Also, just to clarify, are we talking about a ValueError for doing a nansum on an empty array as well, or will that now return a zero? Ben Root On Mon, Jul 15, 2013 at 9:52 AM, Charles R Harris charlesr.har...@gmail.com wrote:

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Sebastian Berg
On Mon, 2013-07-15 at 07:52 -0600, Charles R Harris wrote: On Sun, Jul 14, 2013 at 3:35 PM, Charles R Harris charlesr.har...@gmail.com wrote: snip For nansum, I would expect 0 even in the case of all nans. The point

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Charles R Harris
On Mon, Jul 15, 2013 at 8:25 AM, Benjamin Root ben.r...@ou.edu wrote: This is going to need to be heavily documented with doctests. Also, just to clarify, are we talking about a ValueError for doing a nansum on an empty array as well, or will that now return a zero? I was going to leave

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Charles R Harris
On Mon, Jul 15, 2013 at 8:34 AM, Sebastian Berg sebast...@sipsolutions.netwrote: On Mon, 2013-07-15 at 07:52 -0600, Charles R Harris wrote: On Sun, Jul 14, 2013 at 3:35 PM, Charles R Harris charlesr.har...@gmail.com wrote: snip For nansum, I would expect 0 even

Re: [Numpy-discussion] Allow == and != to raise errors

2013-07-15 Thread Frédéric Bastien
Just a question, should == behave like a ufunc or like python == for tuple? I think that all ndarray comparision (==, !=, =, ...) should behave the same. If they don't (like it was said), making them consistent is good. What is the minimal change to have them behave the same? From my

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Charles R Harris
On Mon, Jul 15, 2013 at 8:34 AM, Sebastian Berg sebast...@sipsolutions.netwrote: On Mon, 2013-07-15 at 07:52 -0600, Charles R Harris wrote: On Sun, Jul 14, 2013 at 3:35 PM, Charles R Harris charlesr.har...@gmail.com wrote: snip For nansum, I would expect 0 even

Re: [Numpy-discussion] Allow == and != to raise errors

2013-07-15 Thread bruno Piguet
Thank-you for your explanations. So, if the operator == applied to np.arrays is a shorthand for the ufunc np.equal, it should definitly behave exactly as np.equal(), and raise an error. One side question about style : In case you would like to protect a x == y test by a try/except clause,

Re: [Numpy-discussion] PIL and NumPy

2013-07-15 Thread Chris Barker - NOAA Federal
On Jul 12, 2013, at 8:51 PM, Brady McCary brady.mcc...@gmail.com wrote: something to do with an alpha channel being present. I'd check and see how PIL is storing the alpha channel. If it's RGBA, then I'd expect it to work. But I'd PIL is storing the alpha channel as a separate band, then I'm

Re: [Numpy-discussion] Allow == and != to raise errors

2013-07-15 Thread bruno Piguet
2013/7/15 Frédéric Bastien no...@nouiz.org Just a question, should == behave like a ufunc or like python == for tuple? That's what I was also wondering. I see the advantage of consistency for newcomers. I'm not experienced enough to see if this is a problem for numerical practitionners Maybe

Re: [Numpy-discussion] read-only or immutable masked array

2013-07-15 Thread Pierre Gerard-Marchant
On Jul 15, 2013, at 14:40 , Gregorio Bastardo gregorio.basta...@gmail.com wrote: Hi Pierre, Note as well that hardening the mask only prevents unmasking: you can still grow the mask, which may not be what you want. Use `x.mask.flags.writeable=False` to make the mask really read-only.

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Charles R Harris
On Mon, Jul 15, 2013 at 8:58 AM, Charles R Harris charlesr.har...@gmail.com wrote: On Mon, Jul 15, 2013 at 8:34 AM, Sebastian Berg sebast...@sipsolutions.net wrote: On Mon, 2013-07-15 at 07:52 -0600, Charles R Harris wrote: On Sun, Jul 14, 2013 at 3:35 PM, Charles R Harris

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Benjamin Root
On Jul 15, 2013 11:47 AM, Charles R Harris charlesr.har...@gmail.com wrote: On Mon, Jul 15, 2013 at 8:58 AM, Charles R Harris charlesr.har...@gmail.com wrote: On Mon, Jul 15, 2013 at 8:34 AM, Sebastian Berg sebast...@sipsolutions.net wrote: On Mon, 2013-07-15 at 07:52 -0600, Charles

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Sebastian Berg
On Mon, 2013-07-15 at 08:47 -0600, Charles R Harris wrote: On Mon, Jul 15, 2013 at 8:34 AM, Sebastian Berg sebast...@sipsolutions.net wrote: On Mon, 2013-07-15 at 07:52 -0600, Charles R Harris wrote: On Sun, Jul 14, 2013 at 3:35 PM, Charles R Harris

Re: [Numpy-discussion] Allow == and != to raise errors

2013-07-15 Thread Sebastian Berg
On Mon, 2013-07-15 at 17:12 +0200, bruno Piguet wrote: 2013/7/15 Frédéric Bastien no...@nouiz.org Just a question, should == behave like a ufunc or like python == for tuple? That's what I was also wondering. I am not sure I understand the question. Of

Re: [Numpy-discussion] PIL and NumPy

2013-07-15 Thread Stéfan van der Walt
Dear Brady On Fri, 12 Jul 2013 22:00:08 -0500, Brady McCary wrote: I want to load images with PIL and then operate on them with NumPy. According to the PIL and NumPy documentation, I would expect the following to work, but it is not. Reading images as PIL is a little bit trickier than one

Re: [Numpy-discussion] read-only or immutable masked array

2013-07-15 Thread Gregorio Bastardo
Ouch… Quick workaround: use `x.harden_mask()` *then* `x.mask.flags.writeable=False` Thanks for the update and the detailed explanation. I'll try this trick. This may change in the future, depending on a yet-to-be-achieved consensus on the definition of 'least-surprising behaviour'. Right

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Charles R Harris
On Mon, Jul 15, 2013 at 9:55 AM, Sebastian Berg sebast...@sipsolutions.netwrote: On Mon, 2013-07-15 at 08:47 -0600, Charles R Harris wrote: On Mon, Jul 15, 2013 at 8:34 AM, Sebastian Berg sebast...@sipsolutions.net wrote: On Mon, 2013-07-15 at 07:52 -0600, Charles R Harris

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Nathaniel Smith
On Mon, Jul 15, 2013 at 6:29 PM, Charles R Harris charlesr.har...@gmail.com wrote: Let me try to summarize. To begin with, the environment of the nan functions is rather special. 1) if the array is of not of inexact type, they punt to the non-nan versions. 2) if the array is of inexact type,

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread josef . pktd
On Mon, Jul 15, 2013 at 2:55 PM, Nathaniel Smith n...@pobox.com wrote: On Mon, Jul 15, 2013 at 6:29 PM, Charles R Harris charlesr.har...@gmail.com wrote: Let me try to summarize. To begin with, the environment of the nan functions is rather special. 1) if the array is of not of inexact type,

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread josef . pktd
On Mon, Jul 15, 2013 at 4:24 PM, josef.p...@gmail.com wrote: On Mon, Jul 15, 2013 at 2:55 PM, Nathaniel Smith n...@pobox.com wrote: On Mon, Jul 15, 2013 at 6:29 PM, Charles R Harris charlesr.har...@gmail.com wrote: Let me try to summarize. To begin with, the environment of the nan functions

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Charles R Harris
On Mon, Jul 15, 2013 at 2:44 PM, josef.p...@gmail.com wrote: On Mon, Jul 15, 2013 at 4:24 PM, josef.p...@gmail.com wrote: On Mon, Jul 15, 2013 at 2:55 PM, Nathaniel Smith n...@pobox.com wrote: On Mon, Jul 15, 2013 at 6:29 PM, Charles R Harris charlesr.har...@gmail.com wrote: Let me try

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread josef . pktd
On Mon, Jul 15, 2013 at 5:34 PM, Charles R Harris charlesr.har...@gmail.com wrote: On Mon, Jul 15, 2013 at 2:44 PM, josef.p...@gmail.com wrote: On Mon, Jul 15, 2013 at 4:24 PM, josef.p...@gmail.com wrote: On Mon, Jul 15, 2013 at 2:55 PM, Nathaniel Smith n...@pobox.com wrote: On Mon, Jul

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Charles R Harris
On Mon, Jul 15, 2013 at 3:57 PM, josef.p...@gmail.com wrote: On Mon, Jul 15, 2013 at 5:34 PM, Charles R Harris charlesr.har...@gmail.com wrote: On Mon, Jul 15, 2013 at 2:44 PM, josef.p...@gmail.com wrote: On Mon, Jul 15, 2013 at 4:24 PM, josef.p...@gmail.com wrote: On Mon, Jul 15,

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Stéfan van der Walt
On Mon, 15 Jul 2013 08:33:47 -0600, Charles R Harris wrote: On Mon, Jul 15, 2013 at 8:25 AM, Benjamin Root ben.r...@ou.edu wrote: This is going to need to be heavily documented with doctests. Also, just to clarify, are we talking about a ValueError for doing a nansum on an empty array as

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Charles R Harris
On Mon, Jul 15, 2013 at 6:22 PM, Stéfan van der Walt ste...@sun.ac.zawrote: On Mon, 15 Jul 2013 08:33:47 -0600, Charles R Harris wrote: On Mon, Jul 15, 2013 at 8:25 AM, Benjamin Root ben.r...@ou.edu wrote: This is going to need to be heavily documented with doctests. Also, just to

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Stéfan van der Walt
On Mon, 15 Jul 2013 18:46:33 -0600, Charles R Harris wrote: So nansum should return zeros rather than the current NaNs? Yes, my feeling is that nansum([]) should be 0. Stéfan ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Benjamin Root
To add a bit of context to the question of nansum on empty results, we currently differ from MATLAB and R in this respect, they return zero no matter what. Personally, I think it should return zero, but our current behavior of returning nans has existed for a long time. Personally, I think we

[Numpy-discussion] retrieving original array locations from 2d argsort

2013-07-15 Thread Moroney, Catherine M (398D)
I know that there's an easy way to solve this problem, but I'm not sufficiently knowledgeable about numpy indexing to figure it out. Here is the problem: Take a 2-d array a, of any size. Sort it in ascending order using, I presume, argsort. Step through the sorted array in order, and for each

Re: [Numpy-discussion] retrieving original array locations from 2d argsort

2013-07-15 Thread Warren Weckesser
On 7/15/13, Moroney, Catherine M (398D) catherine.m.moro...@jpl.nasa.gov wrote: I know that there's an easy way to solve this problem, but I'm not sufficiently knowledgeable about numpy indexing to figure it out. Here is the problem: Take a 2-d array a, of any size. Sort it in ascending

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Charles R Harris
On Mon, Jul 15, 2013 at 6:58 PM, Benjamin Root ben.r...@ou.edu wrote: To add a bit of context to the question of nansum on empty results, we currently differ from MATLAB and R in this respect, they return zero no matter what. Personally, I think it should return zero, but our current behavior

Re: [Numpy-discussion] What should be the result in some statistics corner cases?

2013-07-15 Thread Ralf Gommers
On Tue, Jul 16, 2013 at 3:50 AM, Charles R Harris charlesr.har...@gmail.com wrote: On Mon, Jul 15, 2013 at 6:58 PM, Benjamin Root ben.r...@ou.edu wrote: To add a bit of context to the question of nansum on empty results, we currently differ from MATLAB and R in this respect, they return