数组 - python使用array.reshape,按照官网的example写的,但是却没效果?

查看:139
本文介绍了数组 - python使用array.reshape,按照官网的example写的,但是却没效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

问题:

本意是想将一个shape为(2L,)的array转成一个shape为(2L,1L)的array,因为后续要跟一个(2L,1L)的array相加,尝试reshape(2,1)不成功。

然后上官网找了下reshape函数:numpy.reshape,按照它给的example试了下,发现也不行。

a = np.arange(6).reshape((3,2))
print a 
a.reshape(2,3) 
print a  

结果都是:[[0,1],[2,3],[4,5]]

改成:

np.reshape(a,(2,3))

a.reshape((2,3))

结果都一样,不知道为什么,求解?

解决方案

a = np.reshape(a,(2,3))

文档:

Signature: np.reshape(a, newshape, order='C')
Docstring:
Gives a new shape to an array without changing its data.

这篇关于数组 - python使用array.reshape,按照官网的example写的,但是却没效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆