From 984d56b4d94bf298a197f1567834451acf49cab9 Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Tue, 19 Nov 2024 13:40:38 -0500 Subject: dir rename --- python_originals/xpxp_to_xxpp.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 python_originals/xpxp_to_xxpp.py (limited to 'python_originals/xpxp_to_xxpp.py') diff --git a/python_originals/xpxp_to_xxpp.py b/python_originals/xpxp_to_xxpp.py new file mode 100644 index 0000000..01d0bf2 --- /dev/null +++ b/python_originals/xpxp_to_xxpp.py @@ -0,0 +1,26 @@ + +def xpxp_to_xxpp(S): + """Permutes the entries of the input from xpxp ordering to xxpp ordering. + + Args: + S (array): input even dimensional square matrix or vector + + Returns: + (array): permuted matrix or vector + """ + 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(-1, 2).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