Re: [Numpy-discussion] Indexing 2d arrays by column using an integer array
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( [neighbourhoods[i][perf[neighbourhoods].argmax(axis=1)[i]] >> for i in xrange(neighbourhoods.shape[0])] ) > > ___ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Indexing 2d arrays by column using an integer array
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 mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Indexing 2d arrays by column using an integer array
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, 8, 0]]) using the integer array In [76]: perf[neighbourhoods].argmax(axis=1) Out[76]: array([2, 1, 0, 2, 1, 0, 0, 2, 1]) to produce a 9-element array but can't find a way of applying the indices to the columns rather than the rows. Is this do-able without using loops? The looped version of what I want is np.array( [neighbourhoods[i][perf[neighbourhoods].argmax(axis=1)[i]] for i in xrange(neighbourhoods.shape[0])] ) Regards, -- Will Furnass Doctoral Student Pennine Water Group Department of Civil and Structural Engineering University of Sheffield Phone: +44 (0)114 22 25768 ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion