[英]How to take a 2x2 array and turn it into 2 (2x2) arrays under the same variable name in python?
So I am working with a section of code that needs a set of 2x2 arrays that is essentially 2 copies of the same 2x2 array.因此,我正在处理需要一组 2x2 数组的代码部分,该数组本质上是同一个 2x2 数组的 2 个副本。
The array that I have currently is shaped like:我目前拥有的阵列形状如下:
[[3.00000000e+02 3.16227766e-02]
[4.00000000e+02 1.00000000e-01]]
it is called self.concs.它被称为 self.concs。
I need an array shaped like this:我需要一个形状像这样的数组:
[[[3.00000000e+02 3.16227766e-02]
[4.00000000e+02 1.00000000e-01]]
[[3.00000000e+02 3.16227766e-02]
[4.00000000e+02 1.00000000e-01]]]
I tried np.stack(self.concs,self.concs) however I got the error: TypeError: only integer scalar arrays can be converted to a scalar index我尝试了 np.stack(self.concs,self.concs) 但是我得到了错误:TypeError:只有整数标量数组可以转换为标量索引
How would I go about getting this type of duplicate array?我将如何获得这种类型的重复数组?
np.stack
takes the arrays as a list or collection, not as individual arguments: np.stack
将数组作为列表或集合,而不是作为单独的参数:
>>> np.stack((concs, concs)) # or: np.stack([concs, concs])
array([[[3.00000000e+02, 3.16227766e-02],
[4.00000000e+02, 1.00000000e-01]],
[[3.00000000e+02, 3.16227766e-02],
[4.00000000e+02, 1.00000000e-01]]])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.