19 August 2020
Code
# Import library
import numpy as np
# Create array
x = np.array([1,2,3,4,5])
print(x)
[1 2 3 4 5]
.
# Use np.where()
y = np.where(x%2==0, 'even', 'odd')
# Output
print(y)
Output
['odd' 'even' 'odd' 'even' 'odd']
Any errors in code above?
Please send a message.