Given two arrays, A
(shape: M X C) and B
(shape: N X C), is there a way to subtract each row of A
from each row of B
without using loops? The final output would be of shape (M N X C).
Example
A = np.array([[ 1, 2, 3],
[100, 200, 300]])
B = np.array([[ 10, 20, 30],
[1000, 2000, 3000],
[ -10, -20, -2]])
Desired result (can have some other shape) (edited):
array([[ -9, -18, -27],
[-999, -1998, -2997],
[ 11, 22, 5],
[ 90, 180, 270],
[-900, -1800, -2700],
[ 110, 220, 302]])
Shape: 6 X 3
(Loop is too slow, and "outer" subtracts each element instead of each row)