Re: [Numpy-discussion] Indexing issue with ndarrays

2016-08-26 Thread Sebastian Berg
On Fr, 2016-08-26 at 09:57 -0400, Joseph Fox-Rabinovitz wrote: > > > On Thu, Aug 25, 2016 at 4:37 PM, Sebastian Berg ns.net> wrote: > > On Do, 2016-08-25 at 10:36 -0400, Joseph Fox-Rabinovitz wrote: > > > This issue recently came up on Stack Overflow: http://stackoverfl > > ow.c > > > om/questio

Re: [Numpy-discussion] Indexing issue with ndarrays

2016-08-26 Thread Joseph Fox-Rabinovitz
On Thu, Aug 25, 2016 at 4:37 PM, Sebastian Berg wrote: > On Do, 2016-08-25 at 10:36 -0400, Joseph Fox-Rabinovitz wrote: > > This issue recently came up on Stack Overflow: http://stackoverflow.c > > om/questions/39145795/masking-a-series-with-a-boolean-array. The > > poster attempted to index an n

Re: [Numpy-discussion] Indexing issue with ndarrays

2016-08-25 Thread Sebastian Berg
On Do, 2016-08-25 at 10:36 -0400, Joseph Fox-Rabinovitz wrote: > This issue recently came up on Stack Overflow: http://stackoverflow.c > om/questions/39145795/masking-a-series-with-a-boolean-array. The > poster attempted to index an ndarray with a pandas boolean Series > object (all False), but the

[Numpy-discussion] Indexing issue with ndarrays

2016-08-25 Thread Joseph Fox-Rabinovitz
This issue recently came up on Stack Overflow: http://stackoverflow.com/questions/39145795/masking-a-series-with-a-boolean-array. The poster attempted to index an ndarray with a pandas boolean Series object (all False), but the result was as if he had indexed with an array of integer zeros. Can so

Re: [Numpy-discussion] Indexing with floats

2016-06-10 Thread Fabien
On 06/10/2016 01:48 PM, Robert Kern wrote: https://mail.scipy.org/pipermail/numpy-discussion/2012-December/064705.html https://github.com/numpy/numpy/issues/2810 https://github.com/numpy/numpy/pull/2891 https://github.com/numpy/numpy/pull/3243 https://mail.scipy.org/pipermail/numpy-discussion/201

Re: [Numpy-discussion] Indexing with floats

2016-06-10 Thread Robert Kern
On Fri, Jun 10, 2016 at 12:15 PM, Fabien wrote: > > Hi, > > I really tried to do my homework before asking this here, but I just couldn't find the relevant information anywhere... > > My question is about the rationale behind forbidding indexing with floats, i.e.: > > >>> x[2.] > __main__:1: Visib

[Numpy-discussion] Indexing with floats

2016-06-10 Thread Fabien
Hi, I really tried to do my homework before asking this here, but I just couldn't find the relevant information anywhere... My question is about the rationale behind forbidding indexing with floats, i.e.: >>> x[2.] __main__:1: VisibleDeprecationWarning: using a non-integer number instead o

[Numpy-discussion] Indexing structured masked arrays with multidimensional fields; what with fill_value?

2015-12-01 Thread Gerrit Holl
Hello, usually, a masked array's .fill_value attribute has ndim=0 and the same dtype as the data attribute: In [27]: ar = array((0, [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], 0.0), dtype="int, (2,3)float, float") In [28]: arm = ma.masked_array(ar) In [29]: arm.fill_value.ndim Out[29]: 0 In [31]: arm.

Re: [Numpy-discussion] Indexing NEP draft

2015-11-29 Thread Sebastian Berg
Hey, small update on this. The NEP draft has not changed much, but you can now try the full power of the proposed new indexing types [1]: * arr.oindex[...] # orthogonal/outer indexing * arr.vindex[...] # vectorized (like fancy, but different ;)) * arr.lindex[...] # legacy/fancy indexing

[Numpy-discussion] Indexing NEP draft

2015-11-11 Thread Sebastian Berg
Hi all, at scipy discussing with Nathaniel and others, we thought that maybe we can push for orthogonal type indexing into numpy. Now with the new version out and some other discussions done, I thought it is time to pick it up :). The basic ideas are twofold. First make indexing easier and less c

Re: [Numpy-discussion] Indexing changes in 1.9

2014-02-03 Thread Charles R Harris
On Mon, Feb 3, 2014 at 2:32 PM, Travis Oliphant wrote: > Hey Sebastien, > > I didn't mean to imply that you would need to necessarily work on it. > But the work Jay has done could use review. > > There are also conversations to have about what to do to resolve the > ambiguity that led to the curr

Re: [Numpy-discussion] Indexing changes in 1.9

2014-02-03 Thread Travis Oliphant
Hey Sebastien, I didn't mean to imply that you would need to necessarily work on it. But the work Jay has done could use review. There are also conversations to have about what to do to resolve the ambiguity that led to the current behavior. Thank you or all the great work on the indexing code

Re: [Numpy-discussion] Indexing changes in 1.9

2014-02-03 Thread Sebastian Berg
On Sun, 2014-02-02 at 13:11 -0600, Travis Oliphant wrote: > This sounds like a great and welcome work and improvements. > > Does it make sense to also do something about the behavior of advanced > indexing when slices are interleaved between lists and integers. > > I know that jay borque has some

Re: [Numpy-discussion] Indexing changes in 1.9

2014-02-03 Thread Sebastian Berg
On Mon, 2014-02-03 at 00:41 -0800, Dinesh Vadhia wrote: > Does the numpy indexing refactorizing address the performance of fancy > indexing highlighted in wes mckinney's blog some years back - > http://wesmckinney.com/blog/?p=215 - where numpy.take() was shown to > be preferable than fancy indexing

Re: [Numpy-discussion] Indexing changes in 1.9

2014-02-03 Thread Dinesh Vadhia
Does the numpy indexing refactorizing address the performance of fancy indexing highlighted in wes mckinney's blog some years back - http://wesmckinney.com/blog/?p=215 - where numpy.take() was shown to be preferable than fancy indexing? ___ NumPy-Discu

Re: [Numpy-discussion] Indexing changes in 1.9

2014-02-02 Thread Travis Oliphant
This sounds like a great and welcome work and improvements. Does it make sense to also do something about the behavior of advanced indexing when slices are interleaved between lists and integers. I know that jay borque has some preliminary work to fix this. There are a some straightforward fixe

Re: [Numpy-discussion] Indexing changes in 1.9

2014-02-02 Thread Charles R Harris
On Sun, Feb 2, 2014 at 10:06 AM, Charles R Harris wrote: > Sebastian has done a lot of work to refactor/rationalize numpy indexing. > The changes are extensive enough that it would be good to have more public > review, so here is the release note. > > The NumPy indexing has seen a complete rewrit

[Numpy-discussion] Indexing changes in 1.9

2014-02-02 Thread Charles R Harris
Sebastian has done a lot of work to refactor/rationalize numpy indexing. The changes are extensive enough that it would be good to have more public review, so here is the release note. The NumPy indexing has seen a complete rewrite in this version. This makes > most advanced integer indexing opera

Re: [Numpy-discussion] Indexing changes/deprecations

2013-09-27 Thread Richard Hattersley
On 27 September 2013 13:27, Sebastian Berg wrote: > And most importantly, is there any behaviour thing in the index > machinery that is bugging you, which I may have forgotten until now? > Well, since you asked... I'd *love* to see the fancy indexing behaviour moved to a separate method(s). Yes,

Re: [Numpy-discussion] Indexing changes/deprecations

2013-09-27 Thread Sebastian Berg
On Fri, 2013-09-27 at 08:45 -0700, Jaime Fernández del Río wrote: > > On Fri, Sep 27, 2013 at 5:27 AM, Sebastian Berg > wrote: > > And most importantly, is there any behaviour thing in the > index > machinery that is bugging you, which I may have forgotten >

Re: [Numpy-discussion] Indexing changes/deprecations

2013-09-27 Thread Jaime Fernández del Río
On Fri, Sep 27, 2013 at 5:27 AM, Sebastian Berg wrote: > > And most importantly, is there any behaviour thing in the index > machinery that is bugging you, which I may have forgotten until now? > I find this behavior of boolean indexing a little bit annoying: >>> a = np.arange(12).reshape(3, 4)

Re: [Numpy-discussion] Indexing changes/deprecations

2013-09-27 Thread Sebastian Berg
On Fri, 2013-09-27 at 09:26 -0400, Benjamin Root wrote: > > Boolean indexing could use a facelift. First, consider the following > (albeit minor) annoyance: > Done. Well will be deprecation warnings for the time being, though. > > Next, it would be nice if boolean indexing returned a view

Re: [Numpy-discussion] Indexing changes/deprecations

2013-09-27 Thread Benjamin Root
On Fri, Sep 27, 2013 at 8:27 AM, Sebastian Berg wrote: > Hey, > > since I am working on the indexing. I was wondering about a few smaller > things: > > * 0-d boolean array, `np.array(0)[True]` (will work now) would > give np.array([0]) as a copy, instead of the original array. > I guess

[Numpy-discussion] Indexing changes/deprecations

2013-09-27 Thread Sebastian Berg
Hey, since I am working on the indexing. I was wondering about a few smaller things: * 0-d boolean array, `np.array(0)[True]` (will work now) would give np.array([0]) as a copy, instead of the original array. I guess I could add a FutureWarning or so, but I am not sure and overall t

Re: [Numpy-discussion] Indexing bug

2013-04-05 Thread Aronne Merrelli
On Sun, Mar 31, 2013 at 12:14 AM, Ivan Oseledets wrote: Oh! So it is not a bug, it is a feature, which is completely > incompatible with other array based languages (MATLAB and Fortran). To > me, I can not find a single explanation why it is so in numpy. > Taking submatrices from a matrix is a

Re: [Numpy-discussion] Indexing bug

2013-04-02 Thread Nathaniel Smith
On Sun, Mar 31, 2013 at 6:14 AM, Ivan Oseledets wrote: >> I am using numpy 1.6.1, >> and encountered a wierd fancy indexing bug: >> >> import numpy as np >> c = np.random.randn(10,200,10); >> >> In [29]: print c[[0,1],:200,:2].shape >> (2, 200, 2) >> >> In [30]: print c[[0,1],:200,[0,1]].shape >>

Re: [Numpy-discussion] Indexing bug

2013-03-31 Thread David Cournapeau
On Sun, Mar 31, 2013 at 6:14 AM, Ivan Oseledets wrote: > Message: 2 > Date: Sat, 30 Mar 2013 11:13:35 -0700 > From: Jaime Fern?ndez del R?o > Subject: Re: [Numpy-discussion] Indexing bug? > To: Discussion of Numerical Python > Message-ID: > > Content-Type: text/

Re: [Numpy-discussion] Indexing bug

2013-03-30 Thread Ivan Oseledets
Message: 2 Date: Sat, 30 Mar 2013 11:13:35 -0700 From: Jaime Fern?ndez del R?o Subject: Re: [Numpy-discussion] Indexing bug? To: Discussion of Numerical Python Message-ID: Content-Type: text/plain; charset="iso-8859-1" On Sat, Mar 30, 2013 at 11:01 AM, Ivan Oseledets wrot

Re: [Numpy-discussion] Indexing bug?

2013-03-30 Thread Jaime Fernández del Río
On Sat, Mar 30, 2013 at 11:01 AM, Ivan Oseledets wrote: > I am using numpy 1.6.1, > and encountered a wierd fancy indexing bug: > > import numpy as np > c = np.random.randn(10,200,10); > > In [29]: print c[[0,1],:200,:2].shape > (2, 200, 2) > > In [30]: print c[[0,1],:200,[0,1]].shape > (2, 200) >

[Numpy-discussion] Indexing bug?

2013-03-30 Thread Ivan Oseledets
I am using numpy 1.6.1, and encountered a wierd fancy indexing bug: import numpy as np c = np.random.randn(10,200,10); In [29]: print c[[0,1],:200,:2].shape (2, 200, 2) In [30]: print c[[0,1],:200,[0,1]].shape (2, 200) It means, that here fancy indexing is not working right for a 3d array. Is

Re: [Numpy-discussion] indexing of arbitrary axis and arbitrary slice?

2013-03-18 Thread Chao YUE
Hi Nathaniel, thanks for your reply, it works fine and suffice for my purpose. cheers, Chao On Sat, Mar 16, 2013 at 5:49 PM, Nathaniel Smith wrote: > On 16 Mar 2013 16:41, "Chao YUE" wrote: > > > > Dear all, > > > > Is there some way to index the numpy array by specifying arbitrary axis > an

Re: [Numpy-discussion] indexing of arbitrary axis and arbitrary slice?

2013-03-16 Thread Nathaniel Smith
On 16 Mar 2013 16:41, "Chao YUE" wrote: > > Dear all, > > Is there some way to index the numpy array by specifying arbitrary axis and arbitrary slice, while > not knowing the actual shape of the data? > For example, I have a 3-dim data, data.shape = (3,4,5) > Is there a way to retrieve data[:,0,:]

[Numpy-discussion] indexing of arbitrary axis and arbitrary slice?

2013-03-16 Thread Chao YUE
Dear all, Is there some way to index the numpy array by specifying arbitrary axis and arbitrary slice, while not knowing the actual shape of the data? For example, I have a 3-dim data, data.shape = (3,4,5) Is there a way to retrieve data[:,0,:] by using something like np.retrieve_data(data,axis=2,

Re: [Numpy-discussion] Indexing API

2012-08-07 Thread Nathaniel Smith
On Thu, Jul 19, 2012 at 2:53 PM, Travis Oliphant wrote: > > On Jul 19, 2012, at 3:50 AM, Nathaniel Smith wrote: > >> So the underlying problem with the controversial inplace_increment >> PR[1] is that currently, there's actually nothing in the public numpy >> API that exposes the workings of numpy

Re: [Numpy-discussion] Indexing API

2012-07-19 Thread Travis Oliphant
On Jul 19, 2012, at 3:50 AM, Nathaniel Smith wrote: > So the underlying problem with the controversial inplace_increment > PR[1] is that currently, there's actually nothing in the public numpy > API that exposes the workings of numpy indexing. The only thing you > can do with a numpy index is cal

[Numpy-discussion] Indexing API

2012-07-19 Thread Nathaniel Smith
So the underlying problem with the controversial inplace_increment PR[1] is that currently, there's actually nothing in the public numpy API that exposes the workings of numpy indexing. The only thing you can do with a numpy index is call ndarray.__getattr__ or __setattr__. This is a pretty obvious

Re: [Numpy-discussion] Indexing 2d arrays by column using an integer array

2012-02-13 Thread William Furnass
Thank you, that does the trick. Regards, Will On 13 February 2012 19:39, Travis Oliphant wrote: > I think the following is what you want: > > neighborhoods[range(9),perf[neighbourhoods].argmax(axis=1)] > > -Travis > > > On Feb 13, 2012, at 1:26 PM, William Furnass wrote: > >> np.array( [neighbo

Re: [Numpy-discussion] Indexing 2d arrays by column using an integer array

2012-02-13 Thread Travis Oliphant
I think the following is what you want: neighborhoods[range(9),perf[neighbourhoods].argmax(axis=1)] -Travis On Feb 13, 2012, at 1:26 PM, William Furnass wrote: > np.array( [neighbourhoods[i][perf[neighbourhoods].argmax(axis=1)[i]] > for i in xrange(neighbourhoods.shape[0])] ) ___

[Numpy-discussion] Indexing 2d arrays by column using an integer array

2012-02-13 Thread William Furnass
Hi, Apologies if the following is a trivial question. I wish to index the columns of the following 2D array In [78]: neighbourhoods Out[78]: array([[8, 0, 1], [0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7,

Re: [Numpy-discussion] Indexing empty dimensions with empty arrays

2011-12-28 Thread Jordi Gutiérrez Hermoso
On 28 December 2011 03:33, Ralf Gommers wrote: > > > 2011/12/27 Jordi Gutiérrez Hermoso >> >> On 26 December 2011 14:56, Ralf Gommers >> wrote: >> > >> > >> > On Mon, Dec 26, 2011 at 8:50 PM, wrote: >> >> I have a hard time thinking through empty 2-dim arrays, and don't know >> >> what rules sh

Re: [Numpy-discussion] Indexing empty dimensions with empty arrays

2011-12-28 Thread Travis Oliphant
I agree with Dag, NumPy should provide consistent handling of empty arrays. It does require some work, but it should be at least declared a bug when it doesn't. Travis -- Travis Oliphant (on a mobile) 512-826-7480 On Dec 28, 2011, at 7:45 AM, Dag Sverre Seljebotn wrote: > On 12/28/2011

Re: [Numpy-discussion] Indexing empty dimensions with empty arrays

2011-12-28 Thread Ralf Gommers
On Wed, Dec 28, 2011 at 2:45 PM, Dag Sverre Seljebotn < d.s.seljeb...@astro.uio.no> wrote: > On 12/28/2011 02:21 PM, Ralf Gommers wrote: > > > > > > On Wed, Dec 28, 2011 at 1:57 PM, Dag Sverre Seljebotn > > mailto:d.s.seljeb...@astro.uio.no>> wrote: > > > > On 12/28/2011 01:52 PM, Dag Sverre S

Re: [Numpy-discussion] Indexing empty dimensions with empty arrays

2011-12-28 Thread Dag Sverre Seljebotn
On 12/28/2011 02:21 PM, Ralf Gommers wrote: > > > On Wed, Dec 28, 2011 at 1:57 PM, Dag Sverre Seljebotn > mailto:d.s.seljeb...@astro.uio.no>> wrote: > > On 12/28/2011 01:52 PM, Dag Sverre Seljebotn wrote: > > On 12/28/2011 09:33 AM, Ralf Gommers wrote: > >> > >> > >> 2011/12

Re: [Numpy-discussion] Indexing empty dimensions with empty arrays

2011-12-28 Thread Ralf Gommers
On Wed, Dec 28, 2011 at 1:57 PM, Dag Sverre Seljebotn < d.s.seljeb...@astro.uio.no> wrote: > On 12/28/2011 01:52 PM, Dag Sverre Seljebotn wrote: > > On 12/28/2011 09:33 AM, Ralf Gommers wrote: > >> > >> > >> 2011/12/27 Jordi Gutiérrez Hermoso >> > > >> > >> On 26 De

Re: [Numpy-discussion] Indexing empty dimensions with empty arrays

2011-12-28 Thread Dag Sverre Seljebotn
On 12/28/2011 01:52 PM, Dag Sverre Seljebotn wrote: > On 12/28/2011 09:33 AM, Ralf Gommers wrote: >> >> >> 2011/12/27 Jordi Gutiérrez Hermoso> > >> >> On 26 December 2011 14:56, Ralf Gommers> > wrote: >> > >> > >>

Re: [Numpy-discussion] Indexing empty dimensions with empty arrays

2011-12-28 Thread Dag Sverre Seljebotn
On 12/28/2011 09:33 AM, Ralf Gommers wrote: > > > 2011/12/27 Jordi Gutiérrez Hermoso > > > On 26 December 2011 14:56, Ralf Gommers > wrote: > > > > > > On Mon, Dec 26, 2011 at 8:50 PM,

Re: [Numpy-discussion] Indexing empty dimensions with empty arrays

2011-12-28 Thread Ralf Gommers
2011/12/27 Jordi Gutiérrez Hermoso > On 26 December 2011 14:56, Ralf Gommers > wrote: > > > > > > On Mon, Dec 26, 2011 at 8:50 PM, wrote: > >> I have a hard time thinking through empty 2-dim arrays, and don't know > >> what rules should apply. > >> However, in my code I might want to catch thes

Re: [Numpy-discussion] Indexing empty dimensions with empty arrays

2011-12-26 Thread Jordi Gutiérrez Hermoso
On 26 December 2011 19:56, wrote: > I don't think I ever ran into an empty matrix in matlab, and wouldn't > know how it behaves. I think they behave like Octave matrices. I'm not sure about all cases because I don't have access to Matlab, but I think Matlab handles it about as sanely as Octave:

Re: [Numpy-discussion] Indexing empty dimensions with empty arrays

2011-12-26 Thread josef . pktd
2011/12/26 Jordi Gutiérrez Hermoso : > On 26 December 2011 14:56, Ralf Gommers wrote: >> >> >> On Mon, Dec 26, 2011 at 8:50 PM, wrote: >>> I have a hard time thinking through empty 2-dim arrays, and don't know >>> what rules should apply. >>> However, in my code I might want to catch these cases

Re: [Numpy-discussion] Indexing empty dimensions with empty arrays

2011-12-26 Thread Jordi Gutiérrez Hermoso
On 26 December 2011 14:56, Ralf Gommers wrote: > > > On Mon, Dec 26, 2011 at 8:50 PM, wrote: >> I have a hard time thinking through empty 2-dim arrays, and don't know >> what rules should apply. >> However, in my code I might want to catch these cases rather early >> than late and then having to

Re: [Numpy-discussion] Indexing empty dimensions with empty arrays

2011-12-26 Thread Ralf Gommers
On Mon, Dec 26, 2011 at 8:50 PM, wrote: > On Mon, Dec 26, 2011 at 1:51 PM, Ralf Gommers > wrote: > > > > > > 2011/12/25 Jordi Gutiérrez Hermoso > >> > >> I have been instructed to bring this issue to the mailing list: > >> > >> http://projects.scipy.org/numpy/ticket/1994 > >> > > The issue is

Re: [Numpy-discussion] Indexing empty dimensions with empty arrays

2011-12-26 Thread josef . pktd
On Mon, Dec 26, 2011 at 1:51 PM, Ralf Gommers wrote: > > > 2011/12/25 Jordi Gutiérrez Hermoso >> >> I have been instructed to bring this issue to the mailing list: >> >>   http://projects.scipy.org/numpy/ticket/1994 >> > The issue is this corner case: > idx = [] x = np.array([]) x[

Re: [Numpy-discussion] Indexing empty dimensions with empty arrays

2011-12-26 Thread Ralf Gommers
2011/12/25 Jordi Gutiérrez Hermoso > I have been instructed to bring this issue to the mailing list: > > http://projects.scipy.org/numpy/ticket/1994 > > The issue is this corner case: >>> idx = [] >>> x = np.array([]) >>> x[idx] #works array([], dtype=float64) >>> x[:, idx] #works array([],

[Numpy-discussion] Indexing empty dimensions with empty arrays

2011-12-24 Thread Jordi Gutiérrez Hermoso
I have been instructed to bring this issue to the mailing list: http://projects.scipy.org/numpy/ticket/1994 TIA, - Jordi G. H. ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] Indexing a masked array with another masked array leads to unexpected results

2011-11-04 Thread Joe Kington
On Fri, Nov 4, 2011 at 5:26 AM, Pierre GM wrote: > > On Nov 03, 2011, at 23:07 , Joe Kington wrote: > > > I'm not sure if this is exactly a bug, per se, but it's a very confusing > consequence of the current design of masked arrays… > I would just add a "I think" between the "but" and "it's" befo

Re: [Numpy-discussion] Indexing a masked array with another masked array leads to unexpected results

2011-11-04 Thread Pierre GM
On Nov 03, 2011, at 23:07 , Joe Kington wrote: > I'm not sure if this is exactly a bug, per se, but it's a very confusing > consequence of the current design of masked arrays… I would just add a "I think" between the "but" and "it's" before I could agree. > Consider the following example: > >

[Numpy-discussion] Indexing a masked array with another masked array leads to unexpected results

2011-11-03 Thread Joe Kington
Forgive me if this is already a well-know oddity of masked arrays. I hadn't seen it before, though. I'm not sure if this is exactly a bug, per se, but it's a very confusing consequence of the current design of masked arrays... Consider the following example: import numpy as np x = np.ma.masked_

Re: [Numpy-discussion] Indexing by label in 3rd dimension

2011-09-19 Thread Benjamin Landenberger
Great! Thank you! On 16/09/2011 17:43, Warren Weckesser wrote: > > > On Fri, Sep 16, 2011 at 10:18 AM, Benjamin Landenberger > > wrote: > > Hello list! > > I have an array *mask* of shape (a, b) and another array *intensities* >

Re: [Numpy-discussion] Indexing by label in 3rd dimension

2011-09-16 Thread Warren Weckesser
On Fri, Sep 16, 2011 at 10:18 AM, Benjamin Landenberger < benjamin.landenber...@imtek.uni-freiburg.de> wrote: > Hello list! > > I have an array *mask* of shape (a, b) and another array *intensities* > of shape (N, a, b), where the values in *mask* range from 0 to N-1. It > is somehow similar to la

Re: [Numpy-discussion] Indexing by label in 3rd dimension

2011-09-16 Thread Benjamin Root
On Friday, September 16, 2011, Benjamin Root wrote: > > > On Friday, September 16, 2011, Benjamin Landenberger < benjamin.landenber...@imtek.uni-freiburg.de> wrote: >> Hello list! >> >> I have an array *mask* of shape (a, b) and another array *intensities* >> of shape (N, a, b), where the values i

Re: [Numpy-discussion] Indexing by label in 3rd dimension

2011-09-16 Thread Benjamin Root
On Friday, September 16, 2011, Benjamin Landenberger < benjamin.landenber...@imtek.uni-freiburg.de> wrote: > Hello list! > > I have an array *mask* of shape (a, b) and another array *intensities* > of shape (N, a, b), where the values in *mask* range from 0 to N-1. It > is somehow similar to label

[Numpy-discussion] Indexing by label in 3rd dimension

2011-09-16 Thread Benjamin Landenberger
Hello list! I have an array *mask* of shape (a, b) and another array *intensities* of shape (N, a, b), where the values in *mask* range from 0 to N-1. It is somehow similar to label arrays in scipy.ndimage. Now I want to pick those entries from the first dimension of *intensities* which are given

Re: [Numpy-discussion] Indexing bug in structured arrays(?)

2011-04-02 Thread Chris
Figured out why this does not work. Sorry and thanks. cf ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

[Numpy-discussion] Indexing bug in structured arrays(?)

2011-04-02 Thread Chris Fonnesbeck
I am either getting a nasty bug when indexing structured arrays, or I don't really understand how they work. I have imported some data using genfromtxt and an associated list of dtypes: ndtype=[('include', int), ('year', int), ('month', int), ('day', int), ('deg_day_north', int), ('deg_day_south',

Re: [Numpy-discussion] Indexing a 2-d array with a 1-d mask

2011-02-09 Thread Alok Singhal
On Wed, Feb 9, 2011 at 1:24 AM, Friedrich Romstedt wrote: > 2011/2/8 Alok Singhal : >> In [6]: data2 = numpy.zeros((0, 5), 'd') >> In [7]: mask2 = numpy.zeros(0, 'bool') >> In [8]: data2[mask2] >> >> Traceback (most recent call last): >>

Re: [Numpy-discussion] Indexing a 2-d array with a 1-d mask

2011-02-09 Thread Friedrich Romstedt
Hi, 2011/2/8 Alok Singhal : > Hi, > > I have an NxM array, which I am indexing with a 1-d, length N boolean > array.  For example, with a 3x5 array: > > In [1]: import numpy > In [2]: data = numpy.arange(15) > In [3]: data.shape = 3, 5 > > Now, I want to select rows 0 and 2, so I can do: > > In [4

[Numpy-discussion] Indexing a 2-d array with a 1-d mask

2011-02-08 Thread Alok Singhal
Hi, I have an NxM array, which I am indexing with a 1-d, length N boolean array. For example, with a 3x5 array: In [1]: import numpy In [2]: data = numpy.arange(15) In [3]: data.shape = 3, 5 Now, I want to select rows 0 and 2, so I can do: In [4]: mask = numpy.array([True, False, True]) In [5]

Re: [Numpy-discussion] indexing of rank-0 structured arrays: why not?

2011-01-10 Thread Robert Kern
On Mon, Jan 10, 2011 at 12:15, Nils Becker wrote: > Robert, > > your answer does work: after indexing with () I can then further index > into the datatype. > > In [115]: a_rank_0[()][0] > Out[115]: 0.0 > > I guess I just found the fact confusing that a_rank_1[0] and a_rank_0 > compare and print eq

Re: [Numpy-discussion] indexing of rank-0 structured arrays: why not?

2011-01-10 Thread Nils Becker
Robert, your answer does work: after indexing with () I can then further index into the datatype. In [115]: a_rank_0[()][0] Out[115]: 0.0 I guess I just found the fact confusing that a_rank_1[0] and a_rank_0 compare and print equal but behave differently under indexing. More precisely if I do I

Re: [Numpy-discussion] indexing of rank-0 structured arrays: why not?

2011-01-10 Thread Robert Kern
On Mon, Jan 10, 2011 at 10:08, Nils Becker wrote: > Hi, > > I noticed that I can index into a dtype when I take an element > of a rank-1 array but not if I make a rank-0 array directly. This seems > inconsistent. A bug? Not a bug. Since there is no axis, you cannot use integers to index into a ra

[Numpy-discussion] indexing of rank-0 structured arrays: why not?

2011-01-10 Thread Nils Becker
Hi, I noticed that I can index into a dtype when I take an element of a rank-1 array but not if I make a rank-0 array directly. This seems inconsistent. A bug? Nils In [76]: np.version.version Out[76]: '1.5.1' In [78]: dt = np.dtype([('x', ' in () IndexError: 0-d arrays can't be indexed In [

Re: [Numpy-discussion] indexing question

2010-11-22 Thread John Salvatier
I think that the only speedup you will get is defining an index only once and reusing it. 2010/11/22 Ernest Adrogué : > 22/11/10 @ 14:04 (-0600), thus spake Robert Kern: >> > This way, I get the elements (0,1) and (1,1) which is what >> > I wanted. The question is: is it possible to omit the [0,1]

Re: [Numpy-discussion] indexing question

2010-11-22 Thread Ernest Adrogué
22/11/10 @ 14:04 (-0600), thus spake Robert Kern: > > This way, I get the elements (0,1) and (1,1) which is what > > I wanted. The question is: is it possible to omit the [0,1] > > in the index? > > No, but you can write generic code for it: > > t[np.arange(t.shape[0]), x, y] Thank you. This i

Re: [Numpy-discussion] indexing question

2010-11-22 Thread Ernest Adrogué
22/11/10 @ 11:20 (-0800), thus spake John Salvatier: > I didn't realize the x's and y's were varying the first time around. > There's probably a way to omit it, but I think the conceptually > simplest way is probably what you had to begin with. Build an index by > saying i = numpy.arange(0, t.shape

Re: [Numpy-discussion] indexing question

2010-11-22 Thread Robert Kern
2010/11/21 Ernest Adrogué : > Hi, > > Suppose an array of shape (N,2,2), that is N arrays of > shape (2,2). I want to select an element (x,y) from each one > of the subarrays, so I get a 1-dimensional array of length > N. For instance: > > In [228]: t=np.arange(8).reshape(2,2,2) > > In [229]: t > O

Re: [Numpy-discussion] indexing question

2010-11-22 Thread Ernest Adrogué
22/11/10 @ 11:08 (-0800), thus spake Christopher Barker: > On 11/21/10 11:37 AM, Ernest Adrogué wrote: > >>so you want > >> > >>t[:,x,y] > > > >I tried that, but it's not the same: > > > >In [307]: t[[0,1],x,y] > >Out[307]: array([1, 7]) > > > >In [308]: t[:,x,y] > >Out[308]: > >array([[1, 3], > >

Re: [Numpy-discussion] indexing question

2010-11-22 Thread John Salvatier
I didn't realize the x's and y's were varying the first time around. There's probably a way to omit it, but I think the conceptually simplest way is probably what you had to begin with. Build an index by saying i = numpy.arange(0, t.shape[0]) then you can do t[i, x,y] On Mon, Nov 22, 2010 at 11:0

Re: [Numpy-discussion] indexing question

2010-11-22 Thread Christopher Barker
On 11/21/10 11:37 AM, Ernest Adrogué wrote: >> so you want >> >> t[:,x,y] > > I tried that, but it's not the same: > > In [307]: t[[0,1],x,y] > Out[307]: array([1, 7]) > > In [308]: t[:,x,y] > Out[308]: > array([[1, 3], > [5, 7]]) what is your t? Here's my example, which I think matches wh

Re: [Numpy-discussion] indexing question

2010-11-21 Thread Ernest Adrogué
Hi, 21/11/10 @ 11:28 (-0800), thus spake John Salvatier: > yes use the symbol ':' > > so you want > > t[:,x,y] I tried that, but it's not the same: In [307]: t[[0,1],x,y] Out[307]: array([1, 7]) In [308]: t[:,x,y] Out[308]: array([[1, 3], [5, 7]]) No? -- Ernest

Re: [Numpy-discussion] indexing question

2010-11-21 Thread John Salvatier
yes use the symbol ':' so you want t[:,x,y] 2010/11/21 Ernest Adrogué : > Hi, > > Suppose an array of shape (N,2,2), that is N arrays of > shape (2,2). I want to select an element (x,y) from each one > of the subarrays, so I get a 1-dimensional array of length > N. For instance: > > In [228]: t=

Re: [Numpy-discussion] indexing question

2010-11-21 Thread John Salvatier
read about basic slicing : http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html On Sun, Nov 21, 2010 at 11:28 AM, John Salvatier wrote: > yes use the symbol ':' > > so you want > > t[:,x,y] > > 2010/11/21 Ernest Adrogué : >> Hi, >> >> Suppose an array of shape (N,2,2), that is N arrays

[Numpy-discussion] indexing question

2010-11-21 Thread Ernest Adrogué
Hi, Suppose an array of shape (N,2,2), that is N arrays of shape (2,2). I want to select an element (x,y) from each one of the subarrays, so I get a 1-dimensional array of length N. For instance: In [228]: t=np.arange(8).reshape(2,2,2) In [229]: t Out[229]: array([[[0, 1], [2, 3]],

Re: [Numpy-discussion] Indexing and lookup issues

2010-09-22 Thread Ross Williamson
Thank you Anne I was doing something totally stupid at my end. Ross On Wed, Sep 22, 2010 at 3:42 PM, Anne Archibald wrote: > On 22 September 2010 16:38, Ross Williamson > wrote: >> Hi everyone >> >> I suspect this is easy but I'm stuck >> >> say I have a 1D array: >> >> t = [10,11,12] >> >> an

Re: [Numpy-discussion] Indexing and lookup issues

2010-09-22 Thread Anne Archibald
On 22 September 2010 16:38, Ross Williamson wrote: > Hi everyone > > I suspect this is easy but I'm stuck > > say I have a 1D array: > > t = [10,11,12] > > and a 2D array: > > id = [[0,1,0] > [0,2,0] > [2,0,2]] > > In could in IDL do y = t[id] which would produce: > > y = [[10,11,10] > [10,12,10]

[Numpy-discussion] Indexing and lookup issues

2010-09-22 Thread Ross Williamson
Hi everyone I suspect this is easy but I'm stuck say I have a 1D array: t = [10,11,12] and a 2D array: id = [[0,1,0] [0,2,0] [2,0,2]] In could in IDL do y = t[id] which would produce: y = [[10,11,10] [10,12,10] [12,10,12]] i.e. use the indexes in id on the lookup array t. Is there an easy

Re: [Numpy-discussion] indexing with booleans without making a copy?

2010-09-08 Thread Ernest Adrogué
8/09/10 @ 15:35 (-0400), thus spake Anne Archibald: > 2010/9/8 Ernest Adrogué : > > I have a sorted, flat array: > > > > In [139]: a =np.array([0,1,2,2,2,3]) > > > > Basically, I want views of the areas where there > > are repeated numbers (since the array is sorted, they > > will be contiguous).

Re: [Numpy-discussion] indexing with booleans without making a copy?

2010-09-08 Thread josef . pktd
2010/9/8 Ernest Adrogué : > Hello, > > I have a sorted, flat array: > > In [139]: a =np.array([0,1,2,2,2,3]) > > Basically, I want views of the areas where there > are repeated numbers (since the array is sorted, they > will be contiguous). > > But, of course, to find the numbers that are repeated

Re: [Numpy-discussion] indexing with booleans without making a copy?

2010-09-08 Thread Anne Archibald
2010/9/8 Ernest Adrogué : > I have a sorted, flat array: > > In [139]: a =np.array([0,1,2,2,2,3]) > > Basically, I want views of the areas where there > are repeated numbers (since the array is sorted, they > will be contiguous). > > But, of course, to find the numbers that are repeated > I have to

[Numpy-discussion] indexing with booleans without making a copy?

2010-09-08 Thread Ernest Adrogué
Hello, I have a sorted, flat array: In [139]: a =np.array([0,1,2,2,2,3]) Basically, I want views of the areas where there are repeated numbers (since the array is sorted, they will be contiguous). But, of course, to find the numbers that are repeated I have to use comparison operations that ret

Re: [Numpy-discussion] indexing question

2010-06-21 Thread Wes McKinney
On Mon, Jun 21, 2010 at 7:10 PM, Robert Kern wrote: > On Mon, Jun 21, 2010 at 17:42, Neal Becker wrote: >> Robert Kern wrote: >> >>> On Mon, Jun 21, 2010 at 14:01, Neal Becker wrote: Can I find an efficient way to do this? I have a 2d array, A, 80 rows by 880 columns. I

Re: [Numpy-discussion] indexing question

2010-06-21 Thread Robert Kern
On Mon, Jun 21, 2010 at 17:42, Neal Becker wrote: > Robert Kern wrote: > >> On Mon, Jun 21, 2010 at 14:01, Neal Becker wrote: >>> Can I find an efficient way to do this? >>> >>> I have a 2d array, A, 80 rows by 880 columns. >>> >>> I have a vector, B, of length 80, with scalar indexes. >> >> I as

Re: [Numpy-discussion] indexing question

2010-06-21 Thread Neal Becker
Robert Kern wrote: > On Mon, Jun 21, 2010 at 14:01, Neal Becker wrote: >> Can I find an efficient way to do this? >> >> I have a 2d array, A, 80 rows by 880 columns. >> >> I have a vector, B, of length 80, with scalar indexes. > > I assume you mean 880. > >> I want a vector output C where >> C[

Re: [Numpy-discussion] indexing question

2010-06-21 Thread Robert Kern
On Mon, Jun 21, 2010 at 14:01, Neal Becker wrote: > Can I find an efficient way to do this? > > I have a 2d array, A, 80 rows by 880 columns. > > I have a vector, B, of length 80, with scalar indexes. I assume you mean 880. > I want a vector output C where > C[i] = A[b[i],i] (i=0,879) C = A[b,

[Numpy-discussion] indexing question

2010-06-21 Thread Neal Becker
Can I find an efficient way to do this? I have a 2d array, A, 80 rows by 880 columns. I have a vector, B, of length 80, with scalar indexes. I want a vector output C where C[i] = A[b[i],i] (i=0,879) ___ NumPy-Discussion mailing list NumPy-Discussion@s

Re: [Numpy-discussion] indexing to sort with argsort(..., axis=1)

2010-04-13 Thread Angus McMorland
On 13 April 2010 04:01, Gökhan Sever wrote: > > > On Mon, Apr 12, 2010 at 9:41 PM, Angus McMorland wrote: > >> Hi all, >> >> I want to sort a 2d array along one dimension, with the indices returned >> by argsort, but the subsequent indexing syntax to get the sorted array is >> not obvious. >> >> T

Re: [Numpy-discussion] indexing to sort with argsort(..., axis=1)

2010-04-12 Thread Gökhan Sever
On Mon, Apr 12, 2010 at 9:41 PM, Angus McMorland wrote: > Hi all, > > I want to sort a 2d array along one dimension, with the indices returned by > argsort, but the subsequent indexing syntax to get the sorted array is not > obvious. > > The following works, but I wonder if there is a simpler way

Re: [Numpy-discussion] indexing to sort with argsort(..., axis=1)

2010-04-12 Thread josef . pktd
On Mon, Apr 12, 2010 at 10:41 PM, Angus McMorland wrote: > Hi all, > I want to sort a 2d array along one dimension, with the indices returned by > argsort, but the subsequent indexing syntax to get the sorted array is not > obvious. > The following works, but I wonder if there is a simpler way: >

[Numpy-discussion] indexing to sort with argsort(..., axis=1)

2010-04-12 Thread Angus McMorland
Hi all, I want to sort a 2d array along one dimension, with the indices returned by argsort, but the subsequent indexing syntax to get the sorted array is not obvious. The following works, but I wonder if there is a simpler way: a = np.random.random(size=(5,3)) s = np.argsort(a, axis=1) sorted =

Re: [Numpy-discussion] indexing question

2010-03-30 Thread josef . pktd
On Tue, Mar 30, 2010 at 10:13 AM, Tom K. wrote: > > This one bit me again, and I am trying to understand it better so I can > anticipate when it will happen. > > What I want to do is get rid of singleton dimensions, and index into the > last dimension with an array. > > In [1]: import numpy as np

Re: [Numpy-discussion] indexing question

2010-03-30 Thread Robert Kern
On Tue, Mar 30, 2010 at 09:46, Charles R Harris wrote: > > > On Tue, Mar 30, 2010 at 8:13 AM, Tom K. wrote: >> >> This one bit me again, and I am trying to understand it better so I can >> anticipate when it will happen. >> >> What I want to do is get rid of singleton dimensions, and index into t

  1   2   >