解答例_4_5

解答例:練習問題_4_5 内包表記 (転置行列)

# 例題4_4による行列作成
m, n = 3, 4
ls = [[10*i + j for j in range(n)] for i in range(m)]

# 転置行列作成
ls_trans = [[row[i] for row in ls] for i in range(len(ls[0]))]
ls_trans

[[0, 10, 20], [1, 11, 21], [2, 12, 22], [3, 13, 23]]

タイトルとURLをコピーしました