Subtract a column vector from matrix at specified vector of columns using only broadcast

后端 未结 2 1156
余生分开走
余生分开走 2021-01-19 08:10

I want to subtract a column vector from a numpy matrix using another vector which is index of columns where the first column vector needs to be subtracted from the main mat

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-19 08:33

    We can use np.subtract.at on transposed view of M -

    np.subtract.at(M.T,I,V)
    

提交回复
热议问题