Python Programming - Arrays - Discussion

Discussion Forum : Arrays - General Questions (Q.No. 31)
31.
What is the output of the following NumPy code snippet?
import numpy as np

arr = np.array([1, 2, 3, 4, 5])
result = np.where(arr % 2 == 0, "even", "odd")
print(result)
['odd' 'even' 'odd' 'even' 'odd']
['even' 'odd' 'even' 'odd' 'even']
[False True False True False]
[1 0 1 0 1]
Answer: Option
Explanation:
The code uses np.where() to label even and odd numbers in the array.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.