How to take a 2x2 array and turn it into 2 (2x2) arrays under the same variable name in python?

Viewed 30

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.

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.

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

How would I go about getting this type of duplicate array?

1 Answers

np.stack takes the arrays as a list or collection, not as individual arguments:

>>> 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]]])
Related