如何乘以列表列表的位置

1 python arrays numpy list python-2.7

如何将此列表与python相乘:

A = [ [0.45, 0.89, 0.91],
      [0.5, 0.78, 0.55],
      [0.134, 0.571, 0.142] ]
Run Code Online (Sandbox Code Playgroud)

如何乘以每列,例如0.45*0.5*0.134 = 0.03015; 0.89*0.78*0.571 = 0.3961; 0,91*0.55*0.142 = 0.071071

 [0.03015,0.3961,0.071071]
Run Code Online (Sandbox Code Playgroud)

我怎么能用python做到这一点?

jpp*_*jpp 12

你可以用纯Python做到这一点:

from operator import mul
from functools import reduce  # no need for this in Python 2.x

res = [reduce(mul, i) for i in zip(*A)]
Run Code Online (Sandbox Code Playgroud)

或者您可以使用numpy:

import numpy as np

res = np.prod(A, axis=0)

array([ 0.03015  ,  0.3963882,  0.071071 ])
Run Code Online (Sandbox Code Playgroud)