如何在numpy中更改数组形状? [英] How to change array shapes in in numpy?
本文介绍了如何在numpy中更改数组形状?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我创建一个数组X = np.random.rand(D, 1)
,它的形状为(3,1)
:
If I create an array X = np.random.rand(D, 1)
it has shape (3,1)
:
[[ 0.31215124]
[ 0.84270715]
[ 0.41846041]]
如果我创建自己的数组A = np.array([0,1,2])
,则它的形状为(1,3)
,看起来像
If I create my own array A = np.array([0,1,2])
then it has shape (1,3)
and looks like
[0 1 2]
如何在数组A
上强制形状为(3, 1)
?
How can I force the shape (3, 1)
on my array A
?
推荐答案
You ou can assign a shape tuple directly to numpy.ndarray.shape.
A.shape = (3,1)
这篇关于如何在numpy中更改数组形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文