[Numpy-discussion] indexing (compared to matlab)

Alan G Isaac aisaac@american....
Sat Jul 26 09:12:40 CDT 2008


This is probably the most asked single question.
Use ``ix_``. Example below.

Cheers,
Alan Isaac

>>> import numpy as np
>>> a=np.floor(np.random.rand(5,5)*10)
>>> ind=[1,3]
>>> a[np.ix_(ind,ind)]+=100
>>> a
array([[   9.,    1.,    2.,    8.,    5.],
       [   2.,  102.,    7.,  109.,    0.],
       [   8.,    0.,    2.,    2.,    2.],
       [   1.,  103.,    5.,  101.,    7.],
       [   1.,    4.,    7.,    2.,    3.]])
>>>




More information about the Numpy-discussion mailing list