Mr Dan
Mr Dan

Reputation: 221

minimum value from an 2dArray

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

Answers (3)

Pygirl
Pygirl

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

Heike
Heike

Reputation: 24420

Another option:

A = [[30, 80, 50], [44, 60, 41]]
list(map(min, zip(*A)))

Upvotes: 0

Boseong Choi
Boseong Choi

Reputation: 2596

A = [[30, 80, 50], [44, 60, 41]]
print([min(column) for column in zip(*A)])

output:

[30, 60, 41]

Upvotes: 1

Related Questions