Vous êtes sur la page 1sur 2

This the code I run. I have already fixed think this code and now it work fine.

Looks like the problem was in initialization of b and assert of w.shape. By changing the value of b
as a single constant integer or float value, and remove ‘1’ in the first assert could fix the code.

assert (w.shape == (dim,)) is to check whether the shape of array ‘w’ is the same size with value of ‘dim’. If
yes means correct and does not give any error message.
assert (isinstance(b,int) or isinstance(b,float)) to check whether the variable ‘b’ has integer or float value.

Actually, assert is not very important in the program. This assert function is useful for programmer
because it is used for debugging the code. If the code fixed already we can just remove the assert
codes or make them as comment notes by putting # code.
To give you more understanding of assert I give a couple examples below:
In the first example, we can use assert give error if we type 1 + 1 == 3. On the other hand, it does
not give error message if we type 1 +1 == 2.

In the second example, the assert was used to check type of value of a variable. In this case, we
have variable ‘a’ which has value 7. Then, it is checked whether the value of ‘a’ is a float type
value. And the python give an error because it was an integer. And when we changed into 7.0 it did
not give any error warning.

Vous aimerez peut-être aussi