I have 2D numpy array, with example shape:
>>> a.shape
(48, 160)
and I want to do simple operation between elements or each row, like a[0] - a[1] but for every row against all other rows.
I know how to do it simply by using for loop and iterating rows, but I was wondering if there is some numpy slicing specific instruction, that can do this without using for loops
You can use broadcasting magic to do this.
This is a good broadcasting tutorial. In this case I make a (1, 4, 3) and b (5, 1, 3) and I get a result that’s (5, 4, 3), the difference of every row pair in a and b.