How to Change Data Type From Integer to Boolean


In this example we will show how to change data type from integer to boolean in Python NumPy.

Source Code

import numpy as np

n = np.array([1, 5, 0])
convert_to_bool = n.astype(bool)

print(convert_to_bool)
print(convert_to_bool.dtype)

Output:

[ True  True False]
bool
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments