NumPy 中的 squeeze函数

首页 / Numpy入门教程 / NumPy 中的 squeeze函数

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

numpy.squeeze(arr, axis)
Sr.No. Parameter & 描述
1

arr

输入数组

2

axis

int或int的元组。选择维度中一维条目的子集

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)

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

微服务架构核心20讲 -〔杨波〕

从0开始学微服务 -〔胡忠想〕

罗剑锋的C++实战笔记 -〔罗剑锋〕

编译原理实战课 -〔宫文学〕

Redis核心技术与实战 -〔蒋德钧〕

容量保障核心技术与实战 -〔吴骏龙〕

超级访谈:对话汤峥嵘 -〔汤峥嵘〕

技术领导力实战笔记 2022 -〔TGO 鲲鹏会〕

结构思考力 · 透过结构看思考 -〔李忠秋〕

好记忆不如烂笔头。留下您的足迹吧 :)