Skip to content

Instantly share code, notes, and snippets.

@bboalimoe
Forked from stober/softmax.py
Last active August 30, 2015 14:40
Show Gist options
  • Save bboalimoe/a7442a9e5ae699d0489a to your computer and use it in GitHub Desktop.
Save bboalimoe/a7442a9e5ae699d0489a to your computer and use it in GitHub Desktop.
Softmax in Python
#! /usr/bin/env python
"""
Author: Jeremy M. Stober
Program: SOFTMAX.PY
Date: Wednesday, February 29 2012
Description: Simple softmax function.
"""
import numpy as np
npa = np.array
def softmax(w, t = 1.0):
e = np.exp(npa(w) / t)
dist = e / np.sum(e)
return dist
if __name__ == '__main__':
w = np.array([0.1,0.2])
print softmax(w)
w = np.array([-0.1,0.2])
print softmax(w)
w = np.array([0.9,-10])
print softmax(w)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment