Skip to content

Instantly share code, notes, and snippets.

@ricklentz
Created January 8, 2018 02:31
Show Gist options
  • Save ricklentz/292d684bd1023d99d84b81beb5750120 to your computer and use it in GitHub Desktop.
Save ricklentz/292d684bd1023d99d84b81beb5750120 to your computer and use it in GitHub Desktop.
import numpy as np
def softmax(L):
expL = np.exp(L)
sumExpL = sum(expL)
result = []
for i in expL:
result.append(i*1.0/sumExpL)
return result
# Note: The function np.divide can also be used here, as follows:
# def softmax(L):
# expL(np.exp(L))
# return np.divide (expL, expL.sum())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment