Skip to content

Instantly share code, notes, and snippets.

@psycharo-zz
Created June 3, 2016 08:32
Show Gist options
  • Select an option

  • Save psycharo-zz/5d98951ccd43961e195980a77c7d4c71 to your computer and use it in GitHub Desktop.

Select an option

Save psycharo-zz/5d98951ccd43961e195980a77c7d4c71 to your computer and use it in GitHub Desktop.
N-dim softmax in numpy
import numpy as np
def softmax(x, axis=None):
e_x = np.exp(x - np.max(x, axis=axis, keepdims=True))
return e_x / np.sum(e_x, axis=axis, keepdims=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment