NumPy: sorting 3D array but keeping 2nd dimension assigned to first

后端 未结 2 549
说谎
说谎 2021-01-15 15:03

I have an array that represents poker cards held by players. Each player holds 6 cards and the cards have a value of 1-12 and have a corresponding suit of 1-4.

The f

2条回答
  •  佛祖请我去吃肉
    2021-01-15 16:03

    Are you sorting the values only to see wich one has the highest value?? Because in this case why not use np.max()?:

    deck=np.array([[[  6.,   2.],
                    [ 10.,   1.],
                    [  5.,   1.],
                    [  9.,   2.],
                    [  4.,   1.],
                    [  3.,   2.],
                    [ 11.,   2.]],
                [[  7.,   2.],
                    [ 8.,   1.],
                    [  1.,   1.],
                    [  9.,   2.],
                    [  4.,   1.],
                    [  3.,   2.],
                    [ 12.,   2.]]])
    
    np.max(deck)
    Out[4]: 12.0
    
    np.max(deck[0])
    Out[5]: 11.0
    

提交回复
热议问题