numpy – np.zeros(dim,1) giving datatype not understood

numpy – np.zeros(dim,1) giving datatype not understood

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

numpy – np.zeros(dim,1) giving datatype not understood

Leave a Reply

Your email address will not be published.