Let's say that I have two arrays of size (4000, 3). What I'd like to do in a vectorized fashion is to calculate the L1/Manhattan distance from each vector of the first array to every vector in the second array, so that I'd end up with a (4000, 4000) array.
My current approach is based on splitting up the (4000, 3) into 3 separate arrays of (4000, 1) and doing broadcasting (similar to here: Python alternative for calculating pairwise distance between two sets of 2d points).
However, this approach doesn't really work if I have initial matrices that are different in size, for example, (4000, 4) or (4000, 5). Then my code would break, because it's assuming there are 3 channels.
Therefore, I'd appreciate any help on creating a generalized vectorized approach that can calculate pairwise L1 distances!