np.ceil(多维数组):对多维数组的各个数向上取整
np.floor(多维数组):对多维数组的各个数向下取整
np.expand_dims(x,axis = 0):在x的第一维度上插入一个维度,axis=1,在x的第二个维度上插入一个维度
例如:
x = np.array([[1,2,3],[4,5,6]])
print (x)
print (x.shape)
结果:
[[1 2 3]
[4 5 6]]
(2, 3)
axis = 0:
y = np.expand_dims(x,axis=0)
print (y)
print ("y.shape: ",y.shape)
print ("y[0][1]: ",y[0][1])
[[[1 2 3]
[4 5 6]]]
y.shape: (1, 2, 3)
y[0][1]: [4 5 6]
axis = 1:
y = np.expand_dims(x,axis=1)
print (y)
print( "y.shape: ",y.shape)
print ("y[1][0]: ",y[1][0])
结果:
[[[1 2 3]]
[[4 5 6]]]
y.shape: (2, 1, 3)
y[1][0]: [4 5 6]
原文地址:https://www.cnblogs.com/shuangcao/p/12060428.html
时间: 2024-10-08 07:03:59