7.numpy_fancy_indexing
7.numpy_fancy_indexing
[51 92 14 71 60 20 82 86 74 74]
[71, 86, 14]
[71 86 14]
[[71 86]
[60 20]]
In [10]: x=np.arange(12).reshape(3,4)
rows = np.array([0,1,2])
cols = np.array([2,1,3])
print(x[rows,cols])
# Notice that the first value in the result is X[0, 2], the second is X[1, 1],
# third is X[2, 3].
print(x[1,[2,0,1]])
print(x[1:,[2,0,1]])
print(type(x))
[ 2 5 11]
[6 4 5]
[[ 6 4 5]
[10 8 9]]
<class 'numpy.ndarray'>
[ 0 99 99 3 99 5 6 7 99 9]
[ 0 89 89 3 89 5 6 7 89 9]
[6. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[6. 0. 1. 1. 1. 0. 0. 0. 0. 0.]
localhost:8924/doc/tree/numpy_fancy_indexing.ipynb? 1/1