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) Traceback (most recent call last):File "
>>> np.squeeze(a).shape (10L,)通过np.squeeze()函数转换后,要显示的数组变成了秩为1的数组,即(10,)
参考:
http://blog.csdn.net/zenghaitao0128/article/details/78512715
到此这篇关于numpy的squeeze函数使用方法的文章就介绍到这了,更多相关numpy squeeze内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章:详解Numpy扩充矩阵维度(np.expand_dims, np.newaxis)和删除维度(np.squeeze)的方法
