[英]Numpy array but each 1 is an element
I know that np.ones(3)
gives the following np array: [1, 1, 1]
is there a command in numpy that gives the following: [[1], [1], [1]]
?我知道
np.ones(3)
给出了以下 np 数组: [1, 1, 1]
在 numpy 中是否有一个命令给出以下内容: [[1], [1], [1]]
?
Alternatively, how do I turn the first array (not just for the size of 3, but for an n sized np.ones()
array) into the form of the second one.或者,我如何将第一个数组(不仅仅是 3 的大小,而是一个 n 大小的
np.ones()
数组)转换为第二个数组的形式。
Reshape sounds like an easy general solution here:重塑在这里听起来像是一个简单的通用解决方案:
np.ones(3).reshape(-1, 1)
Although you can always start with this:虽然你总是可以从这个开始:
np.ones((3, 1))
These do the same thing这些做同样的事情
import numpy as np
one=np.ones(3)
one.reshape(3,1,1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.