Numpy "type" versus "dtype"

Convolutional Neural Networks - week 1
(Convolution_model_Step_by_Step_v1)

I am stuck in this check: (for 3 days)
assert (type(Z) == np.float64 or type(Z) == np.float32), “You must cast the output to float”.

I used…
Z = XX.astype(np.float)
print(“1 type(Z)”,type(Z))
print (“2 Z.dtype”,Z.dtype)

I get
1 type(Z) <class ‘numpy.ndarray’>
2 Z.dtype float64

It seams I just cannot make Z type float, only <class ‘numpy.ndarray’>.

Thank you very much,
Ricardo Conte

Hello @contericardo and welcome to Discourse.

What is XX? It is probably a numpy array, and so the output of XX.astype(...) is also a number array, cast to the type in the parenthesis.
In (native) Python you can cast a scalar to float simply by: Z = float(3) , e.g.

1 Like