Skip to content

Instantly share code, notes, and snippets.

@nad2000
Created July 4, 2016 06:54
Show Gist options
  • Save nad2000/6100df204946da558212203ce401dffa to your computer and use it in GitHub Desktop.
Save nad2000/6100df204946da558212203ce401dffa to your computer and use it in GitHub Desktop.
"""Softmax."""
scores = [3.0, 1.0, 0.2]
import numpy as np
def softmax(x):
"""Compute softmax values for each sets of scores in x."""
exp_x = np.exp(x)
return exp_x / exp_x.sum(axis=0)
print(softmax(scores))
# Plot softmax curves
import matplotlib.pyplot as plt
x = np.arange(-2.0, 6.0, 0.1)
scores = np.vstack([x, np.ones_like(x), 0.2 * np.ones_like(x)])
plt.plot(x, softmax(scores).T, linewidth=2)
plt.show()
@kasidkhansbp
Copy link

kasidkhansbp commented Feb 25, 2021

I know this is not the right place but I am unable to find any documentation to learn more about softmax(scores).T (What is .T?) in plt.plot(x, softmax(scores).T, linewidth=2). Any help will be appreciated.

@nad2000
Copy link
Author

nad2000 commented Feb 26, 2021 via email

@kasidkhansbp
Copy link

Thank you @nad2000 for your reply. In case someone comes here looking for the same answer, this what I found and helped me to clarify my doubt. https://stackoverflow.com/questions/5741372/syntax-in-python-t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment