2
我有一個多維陣列NumPy的:索引多維數組以與陣列
In [1]: m = np.arange(1,26).reshape((5,5))
In [2]: m
Out[2]:
array([[ 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20],
[21, 22, 23, 24, 25]])
和另一個數組p = np.asarray([[1,1],[3,3]])
。我想p
作爲指標對m
一個陣列,即:
m[p]
array([7, 19])
但是我得到:
In [4]: m[p]
Out[4]:
array([[[ 6, 7, 8, 9, 10],
[ 6, 7, 8, 9, 10]],
[[16, 17, 18, 19, 20],
[16, 17, 18, 19, 20]]])
我怎樣才能使用p
的m
所需分得一杯羹?
等等......嗯......什麼? – 2013-04-28 08:07:55