Reputation: 221
I have this array:
A = [[30, 80, 50], [44, 60, 41]]
How can I get output like:
min = [30, 60, 41]
Upvotes: 1
Views: 40
Reputation: 13349
import numpy as np
A = [[30, 80, 50], [44, 60, 41]]
np.min(A, axis=0) # computes minimum in each row
Output:
array([30, 60, 41])
Upvotes: 1
Reputation: 24420
Another option:
A = [[30, 80, 50], [44, 60, 41]]
list(map(min, zip(*A)))
Upvotes: 0
Reputation: 2596
A = [[30, 80, 50], [44, 60, 41]]
print([min(column) for column in zip(*A)])
output:
[30, 60, 41]
Upvotes: 1