Python program to calculate harmonic series

后端 未结 11 1895
终归单人心
终归单人心 2020-12-06 19:15

Does anyone know how to write a program in Python that will calculate the addition of the harmonic series. i.e. 1 + 1/2 +1/3 +1/4...

11条回答
  •  再見小時候
    2020-12-06 19:30

    By using the numpy module, you can also alternatively use:

    import numpy as np
    def HN(n):
        return sum(1/arange(1,n+1))
    

提交回复
热议问题