Reputation: 81
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
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