同步操作将从 编程语言算法集/Python 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
"""This script demonstrates the implementation of the Softmax function.Its a function that takes as input a vector of K real numbers, and normalizesit into a probability distribution consisting of K probabilities proportionalto the exponentials of the input numbers. After softmax, the elements of thevector always sum up to 1.Script inspired from its corresponding Wikipedia articlehttps://en.wikipedia.org/wiki/Softmax_function"""import numpy as npdef softmax(vector):"""Implements the softmax functionParameters:vector (np.array,list,tuple): A numpy array of shape (1,n)consisting of real values or a similar list,tupleReturns:softmax_vec (np.array): The input numpy array after applyingsoftmax.The softmax vector adds up to one. We need to ceil to mitigate forprecision>>> np.ceil(np.sum(softmax([1,2,3,4])))1.0>>> vec = np.array([5,5])>>> softmax(vec)array([0.5, 0.5])>>> softmax([0])array([1.])"""# Calculate e^x for each x in your vector where e is Euler's# number (approximately 2.718)exponentVector = np.exp(vector)# Add up the all the exponentialssumOfExponents = np.sum(exponentVector)# Divide every exponent by the sum of all exponentssoftmax_vector = exponentVector / sumOfExponentsreturn softmax_vectorif __name__ == "__main__":print(softmax((0,)))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。