Python Numpy One Hot to Regions

后端 未结 1 1374
悲&欢浪女
悲&欢浪女 2021-01-23 03:49

What is the best way to make this One Hot encoded matrix

array([[[1, 0, 0],
        [1, 0, 0],
        [0, 1, 0]],

       [[0, 0, 1],
        [0, 1, 0],
                


        
相关标签:
1条回答
  • 2021-01-23 04:34

    Use np.argmax along axis=2 -

    a.argmax(2)
    

    Sample run -

    In [186]: a
    Out[186]: 
    array([[[1, 0, 0],
            [1, 0, 0],
            [0, 1, 0]],
    
           [[0, 0, 1],
            [0, 1, 0],
            [1, 0, 0]]])
    
    In [187]: a.argmax(2)
    Out[187]: 
    array([[0, 0, 1],
           [2, 1, 0]])
    
    0 讨论(0)
提交回复
热议问题