[英]Python numpy: column arrays (2d) or lists (1d)
In numpy, is it recommended to create column arrays (2d arrays) rather than 1d arrays? 在numpy中,建议创建列数组(2d数组)而不是1d数组吗? For example, whereas
Z = np.zeros((12,))
defines a 1-dimensional list, it might also be preferable to form Z = np.zeros((12,1))
. 例如,尽管
Z = np.zeros((12,))
定义了一维列表,但最好还是形成Z = np.zeros((12,1))
。
Depends on the use case. 取决于用例。 Both possibilities exist for a reason: if
Z
can be a matrix but just happens to have one column, make it a column vector. 两种可能性的存在是有原因的:如果
Z
可以是矩阵,但恰好只有一列,则使其成为列向量。 If Z
is always a single vector, make it 1-d unless some operation (or library) requires the other format; 如果
Z
始终是单个向量,则将其设置为1-d,除非某些操作(或库)要求另一种格式;否则将其设为1-d。 1-d is usually a bit easier to work with. 1-d通常更容易使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.