[Numpy-discussion] indexing question

Robert Kern robert.kern at gmail.com
Mon Jun 21 15:09:30 EDT 2010


On Mon, Jun 21, 2010 at 14:01, Neal Becker <ndbecker2 at gmail.com> 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, np.arange(880)]

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list