Re: [Numpy-discussion] can argmax be used to return row and column indices?

2013-09-13 Thread Gregorio Bastardo
There's already been some dance around this topic, maybe you will find the concept behind it: http://search.gmane.org/?query=unravel_index&group=gmane.comp.python.numeric.general 2013/9/13 Mark Bakker : > Thanks, Gregorio. > I would like it if argmax had a keyword option to return the row,colum

Re: [Numpy-discussion] can argmax be used to return row and column indices?

2013-09-13 Thread Gregorio Bastardo
Hi Mark, You're looking for "np.unravel_index" function. Cheers, Gregorio 2013/9/13 Mark Bakker : > Hello list, > > I am trying to find the indices of the maximum value in a 2D array. > argmax works fine, but returns the index in the flattened array. > That is often not very convenient. > Is the

Re: [Numpy-discussion] find appropriate dtype based on a set of values

2013-09-05 Thread Gregorio Bastardo
to a float64 array in the second case (same behaviour with np.array). Anyone knows the reason behind? python 2.7.4 win32 numpy 1.7.1 Gregorio 2013/9/4 Gregorio Bastardo : > @Stéfan: the 'np.all' calls are now unnecessary on line 26 > > @Stéfan, Robert: Is it worth to bring th

Re: [Numpy-discussion] find appropriate dtype based on a set of values

2013-09-04 Thread Gregorio Bastardo
@Stéfan: the 'np.all' calls are now unnecessary on line 26 @Stéfan, Robert: Is it worth to bring this solution into numpy? I mean it's probably not a rare problem, and now users have to bring this snippet into their codebase. Gregorio 2013/9/3 Stéfan van der Walt : > On Tue, Sep 3, 2013 at 2:47

Re: [Numpy-discussion] find appropriate dtype based on a set of values

2013-09-03 Thread Gregorio Bastardo
was only curious why this feature is not provided by the function itself, as returning the input array's dtype seems not so useful (can't imagine such a use case). Gregorio 2013/9/2 Stéfan van der Walt : > On Mon, Sep 2, 2013 at 4:21 PM, Gregorio Bastardo > wrote: >>>>>

[Numpy-discussion] find appropriate dtype based on a set of values

2013-09-02 Thread Gregorio Bastardo
Hi, I'd like to find the smallest possible representation of an array given a set of possible values. I've checked the function 'np.min_scalar_type', it works well for scalar input, but contrary to my assumption when array-like param is given: array's dtype is simply returned, instead of finding a

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'. Rig

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 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 a masked

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] 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 overlo

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

2013-07-13 Thread Gregorio Bastardo
ution for this problem? Thanks, Gregorio 2013/7/12 Stéfan van der Walt : > On Fri, Jul 12, 2013 at 4:41 PM, Gregorio Bastardo > wrote: >> array.flags.writeable = False >> >> is perfectly fine, but it does not work on ma-s. Moreover, mask >> hardening only prot

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

2013-07-12 Thread Gregorio Bastardo
Hi, I use masked arrays to mark missing values in data and found it very convenient, although sometimes counterintuitive. I'd like to make a pool of masked arrays (shared between several processing steps) read-only (both data and mask property) to protect the arrays from accidental modification (