If I have an array with 4 int
[a,b,c,d]
and I want a difference between each element to another element, which the result looks like:
[a-b, a-c, a-d,b-c,b-d,c-d]
The sign does matter, I try shift the array, but there should be a better way to do this, Cause this seems like some math problem that I forgot.
import numpy as np
array_1 = np.array([1,2,3,4])
array_2 = np.copy(array_1)
array_2 = np.roll(array_2,-1)
array_2[-1] = 0
array_3 = np.copy(array_2)
array_3 = np.roll(array_3,-1)
array_3[-1] = 0
result_1n2 = array_1-array_2
result_1n3 = array_1-array_3
result_last = array_1[0] - array_1[-1]
array_result = [result_1n2[0],result_1n3[0], result_last, result_1n2[1], result_1n3[1], result_1n2[2]]
print(array_result)
[-1, -2, -3, -1, -2, -1]
How should I approach this?