I have bijections/permutations on a 3d numpy array given as two 3 tuples of numpy arrays. For example my 3d numpy array could look like this
arr = np.array([[[3, 2, 1], [5, 0, 5], [2, 0, 1]],
[[3, 4, 5], [4, 2, 0], [0, 1, 1]],
[[2, 0, 5], [1, 5, 1], [0, 5, 1]],
[[4, 3, 0], [1, 3, 3], [3, 3, 3]],
[[2, 4, 0], [2, 1, 0], [4, 4, 4]],
[[4, 3, 2], [2, 4, 2], [5, 5, 5]]])
And a permutation on it like this:
a, b = ((np.array([5, 2, 2, 2, 1, 1, 1, 4, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0]),
np.array([0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 2, 1, 0, 0, 0, 1, 2, 2, 2, 1]),
np.array([2, 2, 1, 0, 0, 0, 0, 0, 1, 2, 2, 2, 0, 1, 2, 2, 2, 1, 0, 0])),
(np.array([4, 5, 5, 5, 2, 2, 2, 1, 1, 1, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0]),
np.array([0, 2, 1, 0, 0, 0, 0, 0, 1, 2, 0, 0, 2, 1, 0, 0, 0, 1, 2, 2]),
np.array([2, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 2, 2, 2, 1])))
I can apply the map by doing arr[a] = arr[b].
My question is: is there an efficient way to compose two of those bijections? For example I want a function compose for which the two following statements are equivalent
c, d = compose((a, b), (a, b))
arr[c] = arr[d]
and
arr[a] = arr[b]
arr[a] = arr[b]
aandbare uniquely defined, i.e., the coordinate 3-tuples inaare unique.