Quickest way to find the nth largest value in a numpy Matrix

前端 未结 6 1909
孤独总比滥情好
孤独总比滥情好 2020-12-29 06:56

There are lots of solutions to do this for a single array, but what about a matrix, such as:

>>> k
array([[ 35,  48,  63],
       [ 60,  77,  96],
          


        
6条回答
  •  灰色年华
    2020-12-29 07:42

    Using the 'unique' function is a very clean way to do it, but likely not the fastest:

    k = array([[ 35,  48,  63],
               [ 60,  77,  96],
               [ 91, 112, 135]])
    i = numpy.unique(k)[-2]
    

    for the second largest

提交回复
热议问题