numpy.squeeze()的用法
import numpy as np x = np.array([[[0], [1], [2]]]) print('x.shape:',x.shape) x1 = np.squeeze(x)# 从数组的形状中删除单维条目,即把shape中为1的维度去掉 print('x1.shape',x1.shape) x2 = np.squeeze(x,2)# 从数组的形状中删除单维条目,三维删除 print('x2.shape',x2.shape) x3 = np.squeeze(x,0)# 从数组的形状中删除单维条目,一维删除 print('x3.shape',x3.shape)
降维结果:
x.shape: (1, 3, 1) x1.shape (3,) x2.shape (1, 3) x3.shape (3, 1)
天道酬勤 循序渐进 技压群雄