Numpy gcd function

前端 未结 5 1936
萌比男神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条回答
  •  误落风尘
    2020-12-19 02:18

    It seems there is no gcd function yet in numpy. However, there is a gcd function in fractions module. If you need to perform gcd on numpy arrays, you could build a ufunc using it:

    gcd = numpy.frompyfunc(fractions.gcd, 2, 1)
    

提交回复
热议问题