Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Finding Lowest Common Multiple using numpy (for more than two inputs)

So I would like to find the lowest common multiple of 4 or more numbers in python. Now I understand that in numpy, you can just use np.lcm but the function is only restricted to two inputs.

import numpy as np
result = np.lcm(12, 8) # calculating the lcm of 12 and 8
print(result)

24

The question is how do I find the lcm of 3 or more integers using the same lcm function in numpy

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You’d use np.lcm.reduce(), and pass it an array of numbers:

>>> np.lcm.reduce([1, 2, 3, 4])
12
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading