Numpy gcd function

前端 未结 5 1927
萌比男神i
萌比男神i 2020-12-19 01:44

Does numpy have a gcd function somewhere in its structure of modules?

I\'m aware of fractions.gcd but thought a numpy

5条回答
  •  梦毁少年i
    2020-12-19 02:08

    Public service announcement for anyone using Python 3.5

    from math import gcd
    gcd(2, 4)
    

    And if you want to write it yourself in a one-liner:

    def gcd(a: int, b: int): return gcd(b, a % b) if b else a
    

提交回复
热议问题