Skip to content

Instantly share code, notes, and snippets.

@claclacla
Created October 19, 2019 10:25
Show Gist options
  • Save claclacla/655679c28511fcb6d0de521f571d88da to your computer and use it in GitHub Desktop.
Save claclacla/655679c28511fcb6d0de521f571d88da to your computer and use it in GitHub Desktop.
The softmax function implmentation in python
# Softmax function
# SF(M) = e(A[i]) / sum(e(A))
# M: The given matrix
M = np.array([1, 2, 3])
# Calculate the exponential of all elements in the input array
M = np.exp(M)
# Calculate the ratio of the exponential of the parameter and the sum of exponential parameter
M = M / np.sum(M)
print(M)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment