blob: 940d8b859db38042aad72c430e924cf2d6430172 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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]
|