Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python numpy 2D array minimum values

In the array:

np.random.randint(100, size=(10, 2))

array([[ 8, 31],
       [96, 97],
       [26, 31],
       [81, 70],
       [47, 97],
       [95, 84],
       [11, 93],
       [31, 77],
       [25, 45],
       [79, 22]])

I´d like to obtain [8, 22], the minimum values of each column.

How can I get it?

like image 539
Mauro Assis Avatar asked Sep 19 '26 08:09

Mauro Assis


1 Answers

I'm just putting @gtlambert's comment into an answer, since it's probably the best choice. Use the array.min function

x = array([[ 8, 31],
       [96, 97],
       [26, 31],
       [81, 70],
       [47, 97],
       [95, 84],
       [11, 93],
       [31, 77],
       [25, 45],
       [79, 22]])

In [6]: x.min(axis=0)
Out[6]: array([ 8, 22])
like image 115
Garrett R Avatar answered Sep 21 '26 21:09

Garrett R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!