【3】数据分析-1-数据的处理--numpy--3--sequeeze

#从数组的形状中删除单维条目,即把shape中为1的维度去掉

实例:

import numpy as np
x = np.array([[[0], [1], [2]]])

print '\nresult1:"'
print x.shape

xx =np.squeeze(x)
print '\nresult2:"'
print xx
print xx.shape

xxx = np.squeeze(x, axis=0)
print '\nresult3:"'
print xxx
print xxx.shape

xxxx = np.squeeze(x, axis=2)
print '\nresult4:"'
print xxxx
print xxxx.shape


y = np.array([[[0], [1], [2]],[[2], [3], [4]]])
yy =np.squeeze(y)
print '\nresult5:"'
print yy
print yy.shape

实例结果:

result1:"
(1L, 3L, 1L)

result2:"
[0 1 2]
(3L,)

result3:"
[[0]
 [1]
 [2]]
(3L, 1L)

result4:"
[[0 1 2]]
(1L, 3L)

result5:"
[[0 1 2]
 [2 3 4]]
(2L, 3L)

参考资料

https://docs.scipy.org/doc/numpy/reference/generated/numpy.squeeze.html

药企,独角兽,苏州。团队长期招人,感兴趣的都可以发邮件聊聊:tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn