reshape函数:更改数组的维数(注意不是shape大小)
e=NP.arange(10 ) )。
e
array ([ 0,1,2,3,4,5,6,7,8,9 ]
e.reshape (1,1,10 ) )。
array ([ [ 0,1,2,3,4,5,6,7,8,9 ] ]
e.reshape (1,1,10 ) )。
array ([ [ 0,1,2,3,4,5,6,7,8,9 ] ]
e.reshape (1,10,1 ) )。
Array([0],
[1],
[2]、
[3]、
[4]、
[5]、
[6]、
[7]、
[8]、
[9] ) )
squeeze函数:从数组的形式中删除单维条目。 也就是说,从shape中删除1个维
用法: numpy.squeeze(a,axis=None ) )。
1 ) a表示输入的数组
2 ) axis用于指定要删除的维,但指定的维必须是单维。 否则会发生错误。
3 ) axis的值为None、int或tuple of ints,可选。 如果axis为空,则删除所有一维条目;
4 )返回值:数组
5 )不修改原始数组
a=e.reshape (1,1,10 ) ) )。
a
array ([ [ 0,1,2,3,4,5,6,7,8,9 ] ]
NP.squeeze(a ) )。
array ([ 0,1,2,3,4,5,6,7,8,9 ]
画画的时候出现
PLT.plot(a ) )。
跟踪后退(mostrecentcalllast ) :
文件',line 1,in
file ' c :python 27libsite-packagesmatplotlibpy plot.py ',line 3240,in plot
(ret=ax.plot(*Args、**kwargs () ) ) ) ) ) ) ) 652
file ' c :python 27libsite-packagesmatplotlib _ _ init _.py ',line 1710,in inner
(返回函数(ax、*args、**kwargs ) () ) ) ) ) ) ) 652
file ' c :python 27libsite-packagesmatplotlibaxesaxes.py ',line 1437,in plot
forlineinself._get_lines(Args,**kwargs ) :
file ' c :python 27libsite-packagesmatplotlibaxes_ base.py ',line 404,in_grab_next_
forseginself._plot_Args(this,kwargs ) :
file ' c :python 27libsite-packagesmatplotlibaxes_ base.py ',line 384,in _plot_args
x,y=self._xy_from_xy(x,y ) ) )。
file ' c :python 27libsite -包 matplotlibaxesbase.py ',line 246,in _xy_from_xy
' shapes{}and{}'.format(x.shape,y.shape ) )
value error 3360 xandycanbenogreaterthan2- d,buthaveshapes(1L,) and (1L,1l,10L ) )。
PLT.plot(NP.squeeze ) a ) )
[]
plt.show () )
NP.squeeze(a ).shape
(10L,)。
使用np.squeeze ()函数转换时,显示的数组为秩1数组,即(10,)
到此为止,我介绍了关于numpy的squeeze函数的使用方法的文章。 有关更多相关numpy squeeze的内容,请搜索脚本仓库中的以前文章或继续查看以下相关文章: 今后也想继续支持脚本房屋。