Say I have a matrix like the following.
[[1,2]
[3,4]]
I want the number 1 to be returned as the minimum.
Currently I have
a = np.array([[1,2],[3,4]])
min([min(element) for element in a])
>> 1
Is there a more efficient way of doing this?
I don't like my solution above. I tried min(a)
which gives an error. I have read the answers provided in
Find maximum and minimum value of a matrix and I feel that what I have is slightly better?
Given your matrix
>>> import numpy as np
>>> a = np.array([[1,2],[3,4]])
You can just call the min
method off your matrix
>>> a.min()
1
Or call the free function min
and pass in your matrix
>>> np.min(a)
1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With