How to calculate a logistic sigmoid function in Python?

后端 未结 15 1876
情话喂你
情话喂你 2020-11-29 16:14

This is a logistic sigmoid function:

\"enter

I know x. How can I calculate F(x

15条回答
  •  悲哀的现实
    2020-11-29 16:55

    you can calculate it as :

    import math
    def sigmoid(x):
      return 1 / (1 + math.exp(-x))
    

    or conceptual, deeper and without any imports:

    def sigmoid(x):
      return 1 / (1 + 2.718281828 ** -x)
    

    or you can use numpy for matrices:

    import numpy as np #make sure numpy is already installed
    def sigmoid(x):
      return 1 / (1 + np.exp(-x))
    

提交回复
热议问题