Infinite product in Python (using functools)

I want to use it once in a while, so I don't always remember it, so make a note.

prod.py


>>> import functools
>>> import operator
>>> prod = functools.partial(functools.reduce, operator.mul)
>>> print(prod([1, 2, 3]))
6

Excerpt from Docstring.

Documents for functools operator documentation

Simply use numpy

prod.py


>>> import numpy as np
>>> np.prod([1, 2, 3])
6

Recommended Posts

Infinite product in Python (using functools)
Translate using googletrans in Python
Using Python mode in Processing
GUI programming in Python using Appjar
Infinite prime number generator in Python3
Try using LevelDB in Python (plyvel)
Using global variables in python functions
Let's see using input in python
Edit videos in Python using MoviePy
Handwriting recognition using KNN in Python
Try using Leap Motion in Python
Depth-first search using stack in Python
When using regular expressions in Python
GUI creation in python using tkinter 2
Mouse operation using Windows API in Python
Notes using cChardet and python3-chardet in Python 3.3.1.
GUI creation in python using tkinter part 1
(Bad) practice of using this in Python
Try using the Kraken API in Python
Using venv in Windows + Docker environment [Python]
Project Euler # 11 "Maximum Product in Grid" in Python
[FX] Hit oanda-API in Python using Docker
Tweet using the Twitter API in Python
[Python] [Windows] Serial communication in Python using DLL
I tried using Bayesian Optimization in Python
Log in to Slack using requests in Python
Using physical constants in Python scipy.constants ~ constants e ~
Write python modules in fortran using f2py
Draw a tree in Python 3 using graphviz
Notes for using python (pydev) in eclipse
Disease classification in Random Forest using Python
Download files in any format using Python
Parallel task execution using concurrent.futures in Python
Notes on using code formatter in Python
Meaning of using DI framework in Python
Quadtree in Python --2
Python in optimization
CURL in python
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Start using Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python