Suppose I have a matrix **B**, where its elements are *b_ij*(i-th row, j-th column).

I have another matrix **U**, where its columns are *u_j*(j-th column).

How can I multiply each *b_ij* with respect to column *u_j* in **U**, then sum up all the results in each row of **B**? (that is, $ \sum b_{ij}u_j $ for each i)

Thanks.

abodh_ltd
(Abodh Poudyal)
#2
Let me see if I get your problem right: are you talking something like this?

```
b = b.view(1,-1)
for i in range(col_u):
sum = 0
for j in range(length(b)): # iterating through cols in u
sum += b[j]* u[: , i]
A[i,:] = sum
```

1 Like

I am so sorry. I had some typo in the previous version. **A** is a typo, I am trying to sum up the result for each row of **B**. Thanks for your response

Yes, I think you got it. Except for the j, I think it should be in range(col_B * i+1, col_B * (i+1) + 1)