The GCD (Greatest Common Divisor), also referred to as HCF (Highest Common Factor), is the largest number that serves as a common factor for both numbers.
Calculate the highest common factor (HCF) of the following two numbers:
import numpy as np num1 = 6 num2 = 9 x = np.gcd(num1, num2) print(x) |
To determine the highest common factor (HCF) of all values in an array, you can use the reduce() method.
The reduce() method will apply the gcd() function as a universal function (ufunc) to each element, effectively reducing the array by one dimension. |
Calculate the greatest common divisor (GCD) for all the numbers in the following array:
import numpy as np arr = np.array([20, 8, 32, 36, 16]) x = np.gcd.reduce(arr) print(x) |