# Getting Assertion error while executing Exercise 4 - initialize_with_zeros in Logistic_Regression_with_a_Neural_Network_mindset

Hi,

Can someone please tell why I am getting Assertion error while executing Exercise 4 - initialize_with_zeros in Logistic_Regression_with_a_Neural_Network_mindset

def initialize_with_zeros(dim):
“”"
This function creates a vector of zeros of shape (dim, 1) for w and initializes b to 0.

``````Argument:
dim -- size of the w vector we want (or number of parameters in this case)

Returns:
w -- initialized vector of shape (dim, 1)
b -- initialized scalar (corresponds to the bias) of type float
"""

# (≈ 2 lines of code)
# w = ...
# b = ...
``````

Moderator Edit: Code Removed

``````return w, b
``````

## dim = 2 w, b = initialize_with_zeros(dim) ​ assert type(b) == float print ("w = " + str(w)) print ("b = " + str(b)) ​ initialize_with_zeros_test(initialize_with_zeros)

AssertionError Traceback (most recent call last)
in
2 w, b = initialize_with_zeros(dim)
3
----> 4 assert type(b) == float
5 print ("w = " + str(w))
6 print ("b = " + str(b))

AssertionError:

Hi, @Naval_Midha. The `assert` statement tests that the parmeter `b` is of Python object type `float`. It did not pass and so “threw” an `AssertionError`. Python distinguishes between floating point numbers and integers (object type `int`). You have most likely defined `b` as an integer. For example, `x = 2` defines `x` as type `int`. The easiest way to fix this is to include a decimal point: `x = 2.` The Python function `float` also works, i.e. `x = float(2)` but why waste the keystrokes?

2 Likes

Hi Kenb, thanks for your help! It worked. Something new learnt today

As I understand, W is zeros of dimension dim and b is a scalar value of 0.0? I too am getting the assertion error, can’t figure out what I am doing wrong?

AssertionError Traceback (most recent call last)
in
2 w, b = initialize_with_zeros(dim)
3
----> 4 assert type(b) == float
5 print ("w = " + str(w))
6 print ("b = " + str(b))

AssertionError: