LoginSignup
1
0

More than 1 year has passed since last update.

行列の転置と90°回転

Posted at

行列$A$の転置と90°回転を求める。

A = \begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{bmatrix}
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

90°回転

結論

rotate = lambda A: [list(x)[::-1] for x in zip(*A)] 

rotate(A) # [[7, 4, 1], [8, 5, 2], [9, 6, 3]]

転置

結論

transpose = lambda A: [list(x) for x in zip(*A)]

transpose(A) # [[1, 4, 7], [2, 5, 8], [3, 6, 9]]

結論

zipは便利

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0