Write a NumPy program to find rows of a given array of shape (8,3) that contain elements of each row of another given array of shape (2,2)
- برمجة بايثون
- 2021-09-13
- mhanasmh00489829403
الأجوبة
import numpy as np
nums1 = np.random.randint(0,6,(6,4))
nums2 = np.random.randint(0,6,(2,3))
print("Original arrays:")
print(nums1)
print("\n",nums2)
temp = (nums1[..., np.newaxis, np.newaxis] == nums2)
rows = (temp.sum(axis=(1,2,3)) >= nums2.shape[1]).nonzero()[0]
print("\nRows of a given array that contain elements of each row of another given array:")
print(rows)
Sample Output:
Original arrays: [[5 2 5 1] [5 4 1 3] [0 1 1 1] [2 0 4 0] [2 5 1 5] [4 0 4 0]] [[2 3 1] [1 1 4]] Rows of a given array that contain elements of each row of another given array: [0 1 2 4]
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال