I want to calculate all possible pairing differences (without repetition) between the columns of the matrix. What is an efficient / python way to do this?
mat = np.random.normal (size = (10, 3) mat array ([[1.5,7 9, 21,282, 0.7,67,43,473 , -0.46 9, 47, 43], [0.542426004, -0.463, 41,769, -0.4,65,72, 9 75], [0.24196227, -1.91328024, -1.72491783], [-0.56228753, -1.01283112, 0.31424733], [-0.90802408, -1.4123037, 1.46564877], [-0.2257763, 0.0675282, -1.42474819], [-0.54438272, 0.11092259, -1.150 99358], [0.37569802 , -0.6,00,63,86,9, -0.2, 9, 1,6, 375], [-0.6,01,70,661, 1.8,52,27,818, -0.0 , 13, 9, 722], [-1.0,57,71,0 9 3, 0.82254, 91, -1.2,2084,365]])
Differences in the 3 pairs in this matrix (see if the selection of unique combinations of N Switch to, where the order does not matter).
pair_a = mat [,, 0] - mat [:, 1] pair_b = mat [:, 0] - mat [:, 2] jodi_c = mat [:, 1] - mat [,, 2]
There is a (ugly) way. You can easily visualize the large matrix using nested for
loops, but I hope that is a good way.
The result should be another matrix, in which scipy.misc.comb (mat.shape [1], 2)
column and mat.shape [0]
Rows
Combinations of 2 lengths can be found using the following combination:
n = mat [1] me, j = np.triu_indices (n, 1) result = mat [:, i] - mat [:, j]
< / Div>
No comments:
Post a Comment