本文介绍了如何在Python中计算逻辑Sigmoid函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个逻辑S型函数:
This is a logistic sigmoid function:
我知道x.我现在如何在Python中计算F(x)?
I know x. How can I calculate F(x) in Python now?
假设x = 0.458.
Let's say x = 0.458.
F(x)=?
推荐答案这应该做到:
import math def sigmoid(x): return 1 / (1 + math.exp(-x))现在您可以通过以下方式进行测试:
And now you can test it by calling:
>>> sigmoid(0.458) 0.61253961344091512更新:请注意,以上内容主要旨在将给定表达式直接一对一转换为Python代码.它没有经过测试,或者在数字上是可靠的实现.如果您知道您需要一个非常可靠的实现,那么我相信其他人实际上已经对此问题进行了一些思考.
Update: Note that the above was mainly intended as a straight one-to-one translation of the given expression into Python code. It is not tested or known to be a numerically sound implementation. If you know you need a very robust implementation, I'm sure there are others where people have actually given this problem some thought.
更多推荐
如何在Python中计算逻辑Sigmoid函数?
发布评论