Np.zeros assertion error

Already working on Programming Assignment: Logistic Regression with a Neural Network Mindset have problem with correct dtype. Setting b.astype(float) doesn’t work too.

assert type(b) == float

[0. 0.]

AssertionError Traceback (most recent call last)
2 print(b)
3 print(str(b.dtype))
----> 4 assert type(b) == float

If you use np.zeros, then b ends up being a numpy array, right? You can see what is going on by adding a print statement like:

print(f"type(b) = {type(b)}")

Try that and see what happens. You want it to be a scalar value. Also note that you have to be careful because 0 is not a float in python: it’s an integer.

But if that means, an array made by np.zeros is seen as ndarray of int then how to change b to type of float when declaration with arg: dtype=float does not work? And b.astype(float) is seen as float64, not float… The use of compatible float_ does not work too…
In this case the statement assert type(b) == float has no sense!
If I edit the exercise in my offline notebook I get as follows:
w = [0. 0.]
b = [0. 0.]
<class ‘numpy.ndarray’>
Therefore I see it as an error made in the exercise code.
But never mind, I simply misunderstood what to do with b ;D Now I must to think how to set the right shape to w.
Thank you for your time.

Yes, it sounds like you were fundamentally missing the point that b is a scalar. Glad that is clear now. For the w case, note that your array has only 1 dimension. It needs to be a two dimensional object. The argument to np.zeros needs to be a “tuple”, not a list of arguments.

I work now on gradient descent. Due to lack of time I usually work up to a half an hour, so it takes time to go to the end of (overdued) assignment.
Yes, I forgot that b is a scalar of float type. Really don’t know why because this topic I made in the past during Andrew’s Machine Learning course.
Thanks again.