NumPy ufuncLesson 41Free preview
ufunc Finding GCD
This lesson is part of NumPy · All levels
Summary
Calculates the greatest common factor (FPB) of two integers, both in scalar form and in element-wise arrays. GCD values are very useful for simplifying fractions and determining whether two numbers are relatively prime. Similar to LCM, it is also available as a np.gcd.reduce to count multiple numbers at once.
Key points
- Np.gcd(a, b) returns the FPB of two integers.
- Work the elements-wise on the array and receive a number of elements.
- Np.gcd.reduce counts the largest common factor of the entire array.
- GCD of two integers 1 means that they are both relatively prime.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.