介绍
这篇文章主要介绍了numpy中怎么使用挤压函数,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获、下面让小编带着大家一起了解一下。
重塑函数:改变数组的维数(注意不是形状大小)
在祝辞祝辞,e=, np.arange (10) 在祝辞祝辞,e 数组([0,1,2,3,4,5,6,7,8,9)) 在祝辞祝辞,e.reshape (1, 1, 10) 数组([[[0,1,2,3,4,5,6,7,8,9]]]) 在祝辞祝辞,e.reshape (1, 1, 10) 数组([[[0,1,2,3,4,5,6,7,8,9]]]) 在祝辞祝辞,e.reshape (1, 1) 阵列([[[0], ,,,[1], ,,,[2], ,,,[3], ,,,[4], ,,,[5], ,,,[6], ,,,[7], ,,,[8], ,,,[9]]])
挤压函数:从数组的形状中删除单维度条目,即把形状中为1的维度去掉
用法:numpy。挤压(轴=None)
, 1)表示输入的数组;
, 2)轴用于指定需要删除的维度,但是指定的维度必须为单维度,否则将会报错;
, 3)轴的取值可为没有或int或元组整数,可选。若轴为空,则删除所有单维度的条目;
, 4)返回值:数组
, 5)不会修改原数组;
在祝辞祝辞,a =, e.reshape (1, 1, 10) ,在的在的在一个 数组([[[0,1,2,3,4,5,6,7,8,9]]]) 在祝辞祝辞,np.squeeze (a) 数组([0,1,2,3,4,5,6,7,8,9])
体现在画图时
在祝辞祝辞,plt.plot (a) Traceback (most recent call 最后一个): ,File “& lt; stdin>“, line 1,拷贝& lt; module> ,File “C: \ Python27 \ lib \网站\ matplotlib \ pyplot.py",, line 3240年,拷贝的阴谋 时间=ret 才能;ax.plot (* args,, * * kwargs) ,File “C: \ Python27 \ lib \网站\ matplotlib \ __init__.py",, line 1710年,内心的拷贝 return 才能;func (ax,, * args,, * * kwargs) ,File “C: \ Python27 \ lib \网站\ matplotlib \ \ _axes.py"轴;,,line 1437年,拷贝的阴谋 for 才能;line 拷贝self._get_lines (* args,, * * kwargs): ,File “C: \ Python27 \ lib \网站\ matplotlib \ \ _base.py"轴;,,line 404年,_grab_next_args拷贝 for 才能;seg 拷贝self._plot_args(这个,,kwargs): ,File “C: \ Python27 \ lib \网站\ matplotlib \ \ _base.py"轴;,,line 384年,_plot_args拷贝 ,,x, y =, self._xy_from_xy (x, y) ,File “C: \ Python27 \ lib \网站\ matplotlib \ \ _base.py"轴;,,line 246年,_xy_from_xy拷贝 “shapes 才能{},以及{}“.format (x.shape, y.shape)) ValueError: x 以及y 还要be no greater than 二维,,but have shapes (1 l,),以及(1 l, 1 l, 10 l) 在祝辞祝辞,plt.plot (np.squeeze (a)) [& lt; matplotlib.lines.Line2D  object at 0 x00000000146cd940>】 在祝辞祝辞,plt.show ()
在祝辞祝辞,np.squeeze .shape (10 l)
通过np.squeeze()函数转换后,要显示的数组变成了秩为1的数组,即(10)
感谢你能够认真阅读完这篇文章,希望小编分享的“numpy中怎么使用挤压函数”这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!