'how to check if vaules of a matrix and an array are equal in python
Given a matrix mat and an array arr, for each row of the matrix if elements of Column 1 are equal to the corresponding element of the array, then print the corresponding value of Column 2 of the matrix.
mat = np.array([['abc','A'],['def','B'],['ghi','C'],['jkl','D']])
arr = np.array(['abc','dfe','ghi','kjl'])
Solution 1:[1]
Output should be `['A', 'C']``
So above code can be modified as
print(mat[np.where(mat[:,0]=arr)][:,1]
# output ['A' 'C']
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | tripleee |
