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
- برمجة بايثون
- 2021-09-13
- mhanasmh00489829403
الأجوبة
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
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال