🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to NumPy Notes
Topic #40

ufunc Finding LCM


Finding LCM (Lowest Common Multiple)

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

Example

  import numpy as np

num1 = 4
num2 = 6

x = np.lcm(num1, num2)

print(x)

Note: Returns: 12 because that is the lowest common multiple of both numbers (43=12 and 62=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.

Example

  import numpy as np

arr = np.array([3, 6, 9])

x = np.lcm.reduce(arr)

print(x)

Note: Returns: 18 because that is the lowest common multiple of all three numbers (36=18, 63=18 and 9*2=18).

Example

  import numpy as np

arr = np.arange(1, 11)

x = np.lcm.reduce(arr)

print(x)

Want to go beyond the notes?

Join CodingNow 2.0's NumPy course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

ufunc Finding LCM – FAQs

Quick answers about learning ufunc Finding LCM in NumPy.

This free note from CodingNow 2.0 explains ufunc Finding LCM in NumPy — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every NumPy topic on CodingNow 2.0, including ufunc Finding LCM, is 100% free with no signup required.
With focused practice, most students grasp ufunc Finding LCM in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now