Q:

Create two arrays of six elements. Write a NumPy program to count the number of instances of a value occurring in one array on the condition of another array

0

Create two arrays of six elements. Write a NumPy program to count the number of instances of a value occurring in one array on the condition of another array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
x = np.array([10,-10,10,-10,-10,10])
y = np.array([.85,.45,.9,.8,.12,.6])
print("Original arrays:")
print(x)
print(y)
result = np.sum((x == 10) & (y > .5))
print("\nNumber of instances of a value occurring in one array on the condition of another array:")
print(result)

Sample Output:

Original arrays:
[ 10 -10  10 -10 -10  10]
[0.85 0.45 0.9  0.8  0.12 0.6 ]

Number of instances of a value occurring in one array on the condition of another array:
3

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now