From 6187aede8dc13a4fc4d5fd5463574955d702d7f4 Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Tue, 19 Nov 2024 13:00:14 -0500 Subject: initial release --- python_src/xxpp_to_xpxp.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 python_src/xxpp_to_xpxp.py (limited to 'python_src/xxpp_to_xpxp.py') diff --git a/python_src/xxpp_to_xpxp.py b/python_src/xxpp_to_xpxp.py new file mode 100644 index 0000000..940d8b8 --- /dev/null +++ b/python_src/xxpp_to_xpxp.py @@ -0,0 +1,25 @@ +def xxpp_to_xpxp(S): + """Permutes the entries of the input from xxpp ordering to xpxp ordering. + + Args: + S (array): input even dimensional square matrix or array + + Returns: + (array): permuted matrix or array + """ + shape = S.shape + n = shape[0] + + if n % 2 != 0: + raise ValueError("The input array is not even-dimensional") + + n = n // 2 + ind = np.arange(2 * n).reshape(2, -1).T.flatten() + + if len(shape) == 2: + if shape[0] != shape[1]: + raise ValueError("The input matrix is not square") + return S[:, ind][ind] + + return S[ind] + -- cgit v1.2.3