Skip to content

Instantly share code, notes, and snippets.

@techedlaksh
Last active April 15, 2016 08:12
Show Gist options
  • Save techedlaksh/2326c69762c911dc573281f0bc780f35 to your computer and use it in GitHub Desktop.
Save techedlaksh/2326c69762c911dc573281f0bc780f35 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
"""
Author: Laksh Arora
Program: SOFTMAX.PY
Date: Friday, April 15 2016
Description: Simple softmax function.
"""
import numpy as np
npa = np.array
def softmax(w, t = 1.0):
e = np.exp(npa(w) / t)
# can handle 2-D array too!
dist = e / e.sum(axis=0)
return dist
if __name__ == '__main__':
w = np.array([1.0, 2.0, 3.0])
print softmax(w)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment