用列表作为列表索引

a = np.around(10*np.random.random((3, 3)))
b = [0, 1, 2]
c = [0, 1, 2]
print(a)
print(a[b, c])

运行结果如下,利用[0, 1, 2]作为行索引, [0,1, 2]作为列索引,输出了a[0, 0], a[1, 1], a[2, 3]。

猜你喜欢

转载自www.cnblogs.com/loubin/p/11294242.html