Suppose I have the following arrays:
first_array = array([[1, 8, 3, 9, 2],
[2, 6, 4, 1, 9],
[4, 2, 12, 8, 16],
[5, 3, 7, 18, 21],
[6, 20, 4, 8, 24]])
So an array with shape (5, 5)
Now I have a second array, which is a slice of the first:
second_array = array([[1, 8, 3, 9, 2],
[2, 6, 4, 1, 9]])
An array with shape (2, 5).
Now I want to subtract every vector of the first array by the vectors of the second array subsequently(excluding- in the first array- the vector of the second array I'm using to subtract), element-wise. I want to this for every vector of the second array.
So I want to have as an output:
subtracted_array = array([[[1, -2, 1, -8, 7],
[3, -6, 9, -1, 14],
[4, -5, 4, 9, 19],
[5, 12, 1, -1, 22]],
[[-1, 2, -1, 8, -7],
[2, -4, 8, 7, 7],
[3, -3, 3, 17, 12],
[4, 14, 0, 7, 15]]])
So this is an array with shape (2, 4, 5)
How do we do this with broadcasting?