pythonで掛け算をしたいです。

前提
次のような一次元リストと二次元リストの掛け算の仕方が分かりません。

python

mochimochi = [5, 1, 2]columns = [ [0.3, 0.5, 0.6], [0.2, 0.5, 0.6], [0.5, 0.7, 0.9], [0.4, 0.8, 0.2], [0.0, 0.1, 0.9]]

これらのリストを以下のような計算ルールで計算したいです。

python

mochimochi[0]*columns[0][0]+mochimochi[1]*columns[0][1]+mochimochi[2]*columns[0][2] = 5*0.3 + 1*0.5 + 2*0.6 = 3.2mochimochi[0]*columns[1][0]+mochimochi[1]*columns[1][1]+mochimochi[2]*columns[1][2] = 5*0.2 + 1*0.5 + 2*0.6 = 2.7mochimochi[0]*columns[2][0]+mochimochi[1]*columns[2][1]+mochimochi[2]*columns[2][2] = 5*0.5 + 1*0.7 + 2*0.9 = 5.0mochimochi[0]*columns[3][0]+mochimochi[1]*columns[3][1]+mochimochi[2]*columns[3][2] = 5*0.4 + 1*0.8 + 2*0.2 = 3.2mochimochi[0]*columns[4][0]+mochimochi[1]*columns[4][1]+mochimochi[2]*columns[4][2] = 5*0.0 + 1*0.1 + 2*0.9 = 1.9

試したこと

python

mochimochi = [5, 1, 2]columns = [ [0.3, 0.5, 0.6], [0.2, 0.5, 0.6], [0.5, 0.7, 0.9], [0.4, 0.8, 0.2], [0.0, 0.1, 0.9]] for mochi in mochimochi: for column in columns: for colum in column: print(mochi*colum) #出力結果1.52.53.01.02.53.02.53.54.52.04.01.00.00.54.50.30.50.60.20.50.60.50.70.90.40.80.20.00.10.90.61.01.20.41.01.21.01.41.80.81.60.40.00.21.8

よろしくお願いします。

コメントを投稿

0 コメント