0

So if I have a matrix like this:

[ 6 9 4 7]
[ 1 2 3 4]
[ 3 5 9 8] 
[ 5 7 2 4] 

I want to know how many times the first column is the minimum. For example, here the answer would be 2, where the 2nd and 3rd row have column 1 as the minimum. I know we can find the minimum using matrix.min(axis=1) from this, and I think we can use numpy.sum to count the number of rows... but how would I actually know from which column the minimum came from? I there some simple way to accomplish this in numpy?

ocean800
  • 3,489
  • 13
  • 41
  • 73
  • 3
    Consider starting with [argmin](https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.argmin.html#numpy.argmin). – sascha Nov 16 '17 at 03:51
  • 1
    @sascha Thank you! Thats exactly the starting point that I needed – ocean800 Nov 16 '17 at 03:53

1 Answers1

0

Well if it helps anyone else, due to the argmin suggestion, came up with this approach that works for the first column:

np.count_nonzero(np.argmin(matrix,axis=1))

Not sure about the performance of this method over large matrices or anything like that however.. Of course, this doesn't work for anything but checking minimums on the first column

ocean800
  • 3,489
  • 13
  • 41
  • 73