python – Multiply all numeric elements within an array


We have for example the array: [1,2,5,7,12,3,9] How could I multiply all the elements of the array without using a for loop?


What you need is to make use of numpy, it has a method known as prod which multiplies all the elements within an array.

<< import numpy as np
<< a = [1,2,3,4]
<< print(
>> 24

I hope my answer has served you, greetings.

Scroll to Top