目录

squeeze

此函数从给定数组的形状中删除一维条目。 此功能需要两个参数。

numpy.squeeze(arr, axis)

Where,

Sr.No. 参数和描述
1

arr

输入数组

2

axis

int或int的元组。 选择形状中的单维条目的子集

例子 (Example)

import numpy as np  
x = np.arange(9).reshape(1,3,3) 
print 'Array X:' 
print x 
print '\n'  
y = np.squeeze(x) 
print 'Array Y:' 
print y 
print '\n'  
print 'The shapes of X and Y array:' 
print x.shape, y.shape

其输出如下 -

Array X:
[[[0 1 2]
 [3 4 5]
 [6 7 8]]]
Array Y:
[[0 1 2]
 [3 4 5]
 [6 7 8]]
The shapes of X and Y array:
(1, 3, 3) (3, 3)
↑回到顶部↑
WIKI教程 @2018