# Np.zeros assertion error

**URL:** <https://community.deeplearning.ai/t/np-zeros-assertion-error/258613>\
**Category:** Neural Networks and Deep Learning\
**Tags:** coursera-platform\
**Created:** [January 17, 2023, 4:27pm UTC](https://community.deeplearning.ai/t/np-zeros-assertion-error/258613 "2023-01-17T16:27:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrzej\_Krynski](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/andrzej_krynski/32/35627_2.png) [@Andrzej\_Krynski](https://community.deeplearning.ai/u/Andrzej_Krynski)\
**Post date:** [January 17, 2023, 4:27pm UTC](https://community.deeplearning.ai/t/np-zeros-assertion-error/258613/1 "2023-01-17T16:27:30Z")

</div>

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.

> b=np.zeros(2,dtype=float)  
> print(b)  
> print(str(b.dtype))  
> assert type(b) == float

[0. 0.]  
float64

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

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [January 17, 2023, 4:36pm UTC](https://community.deeplearning.ai/t/np-zeros-assertion-error/258613/2 "2023-01-17T16:36:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Andrzej\_Krynski](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/andrzej_krynski/32/35627_2.png) [@Andrzej\_Krynski](https://community.deeplearning.ai/u/Andrzej_Krynski)\
**Post date:** [January 17, 2023, 6:29pm UTC](https://community.deeplearning.ai/t/np-zeros-assertion-error/258613/3 "2023-01-17T18:29:21Z")

</div>

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:  
AssertionError:  
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.

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [January 17, 2023, 6:57pm UTC](https://community.deeplearning.ai/t/np-zeros-assertion-error/258613/4 "2023-01-17T18:57:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Andrzej\_Krynski](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/andrzej_krynski/32/35627_2.png) [@Andrzej\_Krynski](https://community.deeplearning.ai/u/Andrzej_Krynski)\
**Post date:** [January 18, 2023, 2:55pm UTC](https://community.deeplearning.ai/t/np-zeros-assertion-error/258613/5 "2023-01-18T14:55:38Z")

</div>

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.
