I have the following code in Matlab
a= a + b(c,:);
where 'a' is 4524x3 matrix, 'b' is 1131x3 and 'c' is 4524x1.
In Python I have
a[:]+= b[c, :]
Where I get 'a' as 4524x4524x3 matrix. Why does Python create this extra dimension instead of summing the values?
Try this instead:
a[:] += b[c.ravel(), :]
Which is happening since it is c treated as a two dimensional matrix and not one one dimensional array, so unnecessary broadcasting happens. You are basically trying to index a matrix with a 2D array when you need it to be 1D.
c