NumPy Tutorial · NumPy ufunc

ufunc Finding LCM

Learn all about ufunc Finding LCM in this comprehensive tutorial.

5 min read advanced
  • The Lowest Common Multiple is the smallest number that is a common multiple of two numbers.
  • To find the Lowest Common Multiple of all values in an array, you can use the reduce() method.

Finding LCM (Lowest Common Multiple)

The Lowest Common Multiple is the smallest number that is a common multiple of two numbers.

python
Note: Returns: 12 because that is the lowest common multiple of both numbers (4*3=12 and 6*2=12).

Finding LCM in Arrays

To find the Lowest Common Multiple of all values in an array, you can use the reduce() method.

Note: The reduce() method will use the ufunc, in this case the lcm() function, on each element, and reduce the array by one dimension.
python
Note: Returns: 18 because that is the lowest common multiple of all three numbers (3*6=18, 6*3=18 and 9*2=18).
python

Module quiz

2 questions
1

Which of the following is true about ufunc Finding LCM?

2

What is the most common pitfall when working with ufunc Finding LCM?

Answer all questions to submit.