How to compute the greatest common divisor of numbers in Python?

E.g.

gcd(5,10) = 5

E.g.

gcd(5,10) = 5

0 votes

You can use the gcd() function of Numpy to compute the greatest common divisor of numbers.

__If you have only 2 numbers:__

>>> import numpy as np

>>> np.gcd(5,10)

5

>>> np.gcd(15,16)

1

__If you have more than 2 numbers:__

>>> np.gcd.reduce([8,14,16])

2

>>> np.gcd.reduce([8,40,45])

1