How to get element-wise minimum of two arrays in Python

2 Answers

0 votes
import numpy as np

arr1 = [9,  1, 76, 8, 20,  3, 99,  0]
arr2 = [2, 21, 30, 6, 19, 98,  4, 50]

min_arr = np.minimum(arr1, arr2)

print(min_arr)




'''
run:

[ 2  1 30  6 19  3  4  0]

'''

 



answered Feb 28, 2023 by avibootz
0 votes
import numpy as np

arr1 = [9,  1, 76, 8, 20,  3, 99,  0]
arr2 = [2, 21, 30, 6, 19, 98,  4, 50]

min_arr = np.fmin(arr1, arr2)

print(min_arr)




'''
run:

[ 2  1 30  6 19  3  4  0]

'''

 



answered Feb 28, 2023 by avibootz
...