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

  • برمجة بايثون

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.

الأجوبة

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
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...