Method .astype(int) in C2_W1_Lab02_CoffeeRoasting_TF

What does the method .astype(int) in [20] do?

In [20]: yhat = (predictions >= 0.5).astype(int)

If I understand it correctly the expression (predictions >= 0.5), to which this method is applied, is a Boolean expression. Is the method .astype(int) defined to return 1 if the Boolean expression returns True and 0 if it returns False? \

Is this method specific to Numpy or it works in Python even without the Numpy library?

Thanks ahead!

The >= operator will return a boolean.
But we want y_hat to be an integer (so we can do other math with it).
That’s why it’s cast as an int.

1 Like