[Numpy-discussion] Silly array question

Sasha ndarray at mac.com
Fri Apr 7 13:56:02 CDT 2006


One more obfuscated numpy entry:

>>> M[tuple(transpose(I))]
array([ 1,  6, 11,  6])


On 4/7/06, Christopher Barker <Chris.Barker at noaa.gov> wrote:
>
>
>
> Webb Sprague wrote:
> > In R, if you have an Nx2 array of integers, you can use that to index
> > an TxS array, yielding a 1xN result.
>
> this seems to work:
>
> >>> import numpy as N
> >>> I = N.array([[0,0], [1,1], [2,2], [1,1]])
> >>> I
> array([[0, 0],
>         [1, 1],
>         [2, 2],
>         [1, 1]])
>
> >>> M = N. array( [[1, 2, 3, 4], [5, 6, 7, 8], [9,10,11, 12], [13, 14,
> 15, 16]])
>
> >>> M
> array([[ 1,  2,  3,  4],
>         [ 5,  6,  7,  8],
>         [ 9, 10, 11, 12],
>         [13, 14, 15, 16]])
>
> >>> M[I[:,0], I[:,1]]
> array([ 1,  6, 11,  6])
>
> --
> Christopher Barker, Ph.D.
> Oceanographer
>
> NOAA/OR&R/HAZMAT         (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
>
> Chris.Barker at noaa.gov
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting
> language
> that extends applications into web and mobile media. Attend the live
> webcast
> and join the prime developer group breaking into this new coding
> territory!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060407/bfc31232/attachment.html 


More information about the Numpy-discussion mailing list