Fill a matrix from a matrix of indices

后端 未结 1 1779
暖寄归人
暖寄归人 2021-01-13 08:28

I want to fill a matrix from an array of indices :

import numpy as np

indx = [[0,1,2],[1,2,4],[0,1,3],[2,3,4],[0,3,4]]
x = np.zeros((5,5))
for i in range(5)         


        
相关标签:
1条回答
  • 2021-01-13 09:06

    Use advanced-indexing after intialization -

    x[np.arange(len(indx))[:,None], indx] = 1
    
    0 讨论(0)
提交回复
热议问题