Scale rows of 3D-tensor

前端 未结 1 1888
忘了有多久
忘了有多久 2020-12-12 06:30

I have an n-by-3-by-3 numpy array A and an n-by-3 numpy array B. I\'d now like to

相关标签:
1条回答
  • 2020-12-12 07:05

    You can use NumPy broadcasting to let the elementwise multiplication happen in a vectorized manner after extending B to 3D after adding a singleton dimension at the end with np.newaxis or its alias/shorthand None. Thus, the implementation would be A*B[:,:,None] or simply A*B[...,None].

    0 讨论(0)
提交回复
热议问题