擅长:python、mysql、java
<p>你可以用这样的方法:</p>
<pre><code>import numpy as np
my_array = np.array([1,2,3,4,5])
result = np.prod(my_array)
#Prints 1*2*3*4*5
print(result)
</code></pre>
<p><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.prod.html" rel="nofollow noreferrer">Here is the documentation of numpy.prod</a><br/>
以下是上述链接的节选:</p>
<blockquote>
<p>By default, calculate the product of all elements:</p>
<pre><code>>>> np.prod([1.,2.])
2.0
</code></pre>
<p>Even when the input array is two-dimensional:</p>
<pre><code>>>> np.prod([[1.,2.],[3.,4.]])
24.0
</code></pre>
<p>But we can also specify the axis over which to multiply:</p>
<pre><code>>>> np.prod([[1.,2.],[3.,4.]], axis=1)
array([ 2., 12.])
</code></pre>
</blockquote>