import numpy as np
eye=np.eye(5)
print("eye:\n",eye)
print("index:\n",eye[[1,0,2]])
取一个矩阵的相应维度时,可用matic[[i,j,k]],注意是两个中括号
输出:
eye:
[[1. 0. 0. 0. 0.]
[0. 1. 0. 0. 0.]
[0. 0. 1. 0. 0.]
[0. 0. 0. 1. 0.]
[0. 0. 0. 0. 1.]]
index:
[[0. 1. 0. 0. 0.]
[1. 0. 0. 0. 0.]
[0. 0. 1. 0. 0.]]