Close this search box.

Introduction to Python Numpy HCF

In This Article, You Will Learn About Python Numpy HCF.

Python Numpy HCF – Before moving ahead, let’s know a bit of Python Numpy LCM


View of GCD

GCD is also known as HCF (Highest Common Factor). It is the highest common number that divides both numbers.

Example – Finding the HCF of both numbers.

					import numpy as np

Num_1 = 20
Num_2 = 10

z = np.gcd(Num_1, Num_2)

Output –


Because 2 is the only highest common value or factor that is in both 3 and 6 Table.

As shown above, it returned two as HCF of given numbers.

HCF in Arrays

Using reduce() method to find the Highest Common Factor of all values of an array.

The reduce() technique will use the ufunc with the gcd() function to on each element to reduce the array by one size.

Example – Finding HCF of the values of the array.

					import numpy as np

array = np.array([12, 16, 22])        

x = np.gcd.reduce(array)


Output -


Because 6 is the only lowest common multiple value that is present in 2, 3, and 6 Table.

2*3=6    3*2=6    6*1=6

As shown above, it returned six as HCF of given numbers.

Example – Finding the HCF of the all integers from 11 to 20.

					import numpy as np

Num = np.arange(11, 21)

z = np.gcd.reduce(Num)



As a result, it returned 1 as HCF of the given range.

If you find anything incorrect in the above-discussed topic and have any further questions, please comment below.

Recent Post

Popular Post

Top Articles


Share on