NumPy 中的 squeeze函数

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

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

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

arr

输入数组

无涯教程网

2

axis

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

链接:https://www.learnfk.comhttps://www.learnfk.com/numpy/numpy-squeeze.html

来源:LearnFk无涯教程网

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)

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

技术教程推荐

全栈工程师修炼指南 -〔熊燚(四火)〕

TensorFlow 2项目进阶实战 -〔彭靖田〕

分布式数据库30讲 -〔王磊〕

手机摄影 -〔@随你们去〕

物联网开发实战 -〔郭朝斌〕

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

Go 语言项目开发实战 -〔孔令飞〕

郭东白的架构课 -〔郭东白〕

深入拆解消息队列47讲 -〔许文强〕

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