Runeater DaWizKid
Runeater DaWizKid

Reputation: 81

Transform matrix via rotation of values

How would you go about transofrming the values of a matrix from

A=
[0, 1, 2]
[-1, 0, 1]
[-2, -1, 0]

To this:

[0, -1, -2]
[1, 0, -1]
[2, 1, 0]

The operation is a mirror over the y=-x axis

Upvotes: 0

Views: 26

Answers (1)

U13-Forward
U13-Forward

Reputation: 71580

In numpy, do .T:

>>> A = np.array([[0, 1, 2],
[-1, 0, 1],
[-2, -1, 0]])
>>> A.T
array([[ 0, -1, -2],
       [ 1,  0, -1],
       [ 2,  1,  0]])
>>>

In regular python, do zip:

>>> A = [[0, 1, 2],
[-1, 0, 1],
[-2, -1, 0]]
>>> list(zip(*A))
[(0, -1, -2), (1, 0, -1), (2, 1, 0)]
>>> 

Upvotes: 1

Related Questions