I am very new to python and numpy. I'm trying to initialize a Row Vector with zeros as follows:
w = np.zeros(dim,1)
I'm getting the error TypeError: data type not understood
. I appreciate any help. Thanks
See the documentation on np.zeros
If you call it the way you did, the size is dim
, and the data type argument dtype
is 1
, which is not a valid data type.
The solution is
import numpy as np
dim = 3 # number of entries
shp = (dim, 1) # shape tuple
x = np.zeros(shp) # second argument 'dtype' is not used, default is 'float'
print(x)
You should call is like:
w = np.zeros((dim, 1))
Based on the docs:
numpy.zeros(shape, dtype=float, order='C')
In this case (dim,1) is the shape
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