I am trying to create a 4 dimensional matrix in python using the following code;
import numpy as np
rho=np.zeros(2,2,2,2)
But I get the following error;
rho=np.zeros(2,2,2,2)
TypeError: function takes at most 3 arguments (4 given)
This seems to work in matlab, but not here. Any help would be appreciated, Thanks!
Instead of passing 4 arguments, pass one argument, a tuple of four elements:
>>> rho=np.zeros((2,2,2,2))
>>> rho
array([[[[ 0., 0.],
[ 0., 0.]],
[[ 0., 0.],
[ 0., 0.]]],
[[[ 0., 0.],
[ 0., 0.]],
[[ 0., 0.],
[ 0., 0.]]]])
>>> rho.shape
(2, 2, 2, 2)
The call signature is zeros(shape, dtype=float, order='C')
, and so it's trying to interpret the first 2 as the shape, the second 2 as the type, the third 2 as the storage order, and then it doesn't know what to do with the last 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With