Suppose the following numpy array:
arr = np.array([0, 1, 2, 3, 4]) # can be any array
I want to know the fastest way to generate the following operation:
n = arr.shape[0]
result = np.tile(arr, (n, 1)) - arr.reshape((-1, 1))
print(result):
array([[ 0, 1, 2, 3, 4],
[-1, 0, 1, 2, 3],
[-2, -1, 0, 1, 2],
[-3, -2, -1, 0, 1],
[-4, -3, -2, -1, 0]])
(1) How to efficiently create matrix "result" (because n >> 0 can be very large) ?
(2) Does this matrix have a particular name ?