numpy中的array([,])

array([: , x])函数

例子1:

import numpy as np

a=np.array(
  [[1 , 2, 3],
  [4, 5 , 6],
  [7, 8, 9 ]])

print(a[:,0])  # [1 4 7]
print(a[:,1])  # [2 5 8]
print(a[:,2])  # [3 6 9]


例子2:

解释

a.shape = (2, 3, 4)
a[x,y,z]
x:第0个维度
y:第1个维度
z:第2个维度
a[:, : , 3 ]
从第2个维度中取出

import numpy as np
b=np.array(
  [[
  [1 , 2, 3, 4],
  [5 , 6, 7, 8],
  [9, 10, 11, 12]
  ],
  [
  [9, 10, 11, 12],
  [5, 6,  7,  8],
  [1, 2,  3,  4],
  ]]
)
print(b.shape)  #  (2, 3, 4)
print(b[:,:,2])
print(b[:,:,3])
结果1[[ 3  7 11]
 [11  7  3]]
结果2[[ 4  8 12]
 [12  8  4]]

你可能感兴趣的:(Python知识点,numpy,python)