[Numpy-discussion] Fancy indexing question:

Ravi lists_ravi@lavabit....
Tue Feb 24 14:26:39 CST 2009


On Tuesday 24 February 2009 14:39:39 Christopher Barker wrote:
> I'm having a bit of trouble getting fancy indexing to do what I want.

Use ix_:

In [2]: a
Out[2]:
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11],
       [12, 13, 14, 15],
       [16, 17, 18, 19],
       [20, 21, 22, 23]])

In [3]: i = array( [1,3,4] )

In [4]: j = array( [1,3] )

In [5]: a[ ix_(i,j) ]
Out[5]:
array([[ 5,  7],
       [13, 15],
       [17, 19]])

Regards,
Ravi




More information about the Numpy-discussion mailing list