[Numpy-discussion] Silly array question

Sasha ndarray at mac.com
Fri Apr 7 12:53:03 EDT 2006


>>> M.ravel()[dot(I,(4,1))]
array([ 1,  6, 11,  6])


On 4/7/06, Webb Sprague <webb.sprague at gmail.com> wrote:
>
> In R, if you have an Nx2 array of integers, you can use that to index
> an TxS array, yielding a 1xN result. Is there a way to do that in
> numpy? I looked for a pairs function but I coudn't find it, vaguely
> remembering that might be around...  I know it would be a trivial loop
> to write, but a numpy array function would be faster (I hope).
>
> Example
>
> I = [[0,0], [1,1], [2,2], [1,1]]
> M = [[1, 2, 3, 4],
>         [5, 6, 7, 8],
>         [9,10,11, 12],
>         [13, 14, 15, 16]]
>
> M[I] = [1,6,11,6].
>
> Thanks!
>
>
> -------------------------------------------------------
> 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?cmdlnk&kid0944&bid$1720&dat1642
> _______________________________________________
> 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://mail.python.org/pipermail/numpy-discussion/attachments/20060407/b9f72dcc/attachment-0001.html>


More information about the NumPy-Discussion mailing list