+2 votes
in Programming Languages by (14.6k points)
How to compute the lowest common multiple of numbers in Python?

E.g.

lcm(10,12) = 60

1 Answer

0 votes
by (25.6k points)

Numpy has a function lcm(). You can use it to compute the lowest common multiple of numbers.

If you have only 2 numbers:

>>> import numpy as np
>>> np.lcm(10,12)
60

If you have more than 2 numbers:

>>> np.lcm.reduce([10,12,15,18,17])
3060
>>> np.lcm.reduce([2,4,8,12])
24

...