compute difference of all the combinations of 2 arrays 1

compute difference of all the combinations of 2 arrays

a = np.arange(0,3)
b = np.arange(1,6)
aa, bb = np.meshgrid(a,b)
aa-bb

Here is what the above code is Doing:
1. aa is a 3×5 matrix with values 0,1,2 repeated 5 times
2. bb is a 3×5 matrix with values 1,2,3,4,5 repeated 3 times
3. aa-bb is a 3×5 matrix with values -1,-1,-1,-1,-1, 0,0,0,0,0, 1,1,1,1,1

Similar Posts