In [1]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
In [11]:
a = np.random.randn(10)
print (a)
softmax_a = np.exp(a)/(np.exp(a)).sum()
[-0.75012973 -0.18956858 1.51197011 -0.33174648 -0.2694382 -0.37770367
0.62610047 1.21066731 -0.81823531 0.41159655]
In [12]:
plt.subplot(1, 2, 1)
plt.scatter(np.arange(0,len(a),1),a,color='red')
plt.subplot(1, 2, 2)
plt.scatter(np.arange(0,len(a),1),softmax_a,color='blue')
plt.show()
In [9]:
b = np.random.randn(100,2)
expb = np.exp(b)
softmax_b = expb/expb.sum(axis=1,keepdims=True)
In [10]:
softmax_b
Out[10]:
array([[ 0.35750486, 0.64249514],
[ 0.19555827, 0.80444173],
[ 0.53055452, 0.46944548],
[ 0.7761232 , 0.2238768 ],
[ 0.21138047, 0.78861953],
[ 0.63550496, 0.36449504],
[ 0.68436883, 0.31563117],
[ 0.15569814, 0.84430186],
[ 0.80364596, 0.19635404],
[ 0.3476126 , 0.6523874 ],
[ 0.65752491, 0.34247509],
[ 0.61311472, 0.38688528],
[ 0.16574904, 0.83425096],
[ 0.3930068 , 0.6069932 ],
[ 0.59859201, 0.40140799],
[ 0.50577143, 0.49422857],
[ 0.89693007, 0.10306993],
[ 0.52342696, 0.47657304],
[ 0.42442864, 0.57557136],
[ 0.36940257, 0.63059743],
[ 0.28305826, 0.71694174],
[ 0.72315451, 0.27684549],
[ 0.89954178, 0.10045822],
[ 0.75519784, 0.24480216],
[ 0.26612509, 0.73387491],
[ 0.80852512, 0.19147488],
[ 0.68416325, 0.31583675],
[ 0.03307317, 0.96692683],
[ 0.21722068, 0.78277932],
[ 0.91672443, 0.08327557],
[ 0.70196835, 0.29803165],
[ 0.68216145, 0.31783855],
[ 0.20112925, 0.79887075],
[ 0.28954934, 0.71045066],
[ 0.31177354, 0.68822646],
[ 0.82962645, 0.17037355],
[ 0.47444812, 0.52555188],
[ 0.26555047, 0.73444953],
[ 0.70177587, 0.29822413],
[ 0.81570155, 0.18429845],
[ 0.63703838, 0.36296162],
[ 0.37021558, 0.62978442],
[ 0.8988664 , 0.1011336 ],
[ 0.1836353 , 0.8163647 ],
[ 0.8501772 , 0.1498228 ],
[ 0.3266048 , 0.6733952 ],
[ 0.82310144, 0.17689856],
[ 0.8503917 , 0.1496083 ],
[ 0.39810817, 0.60189183],
[ 0.90085117, 0.09914883],
[ 0.07806474, 0.92193526],
[ 0.29331349, 0.70668651],
[ 0.11028056, 0.88971944],
[ 0.31239047, 0.68760953],
[ 0.66248275, 0.33751725],
[ 0.53678111, 0.46321889],
[ 0.97721598, 0.02278402],
[ 0.51967683, 0.48032317],
[ 0.73667322, 0.26332678],
[ 0.22534681, 0.77465319],
[ 0.6268907 , 0.3731093 ],
[ 0.43629279, 0.56370721],
[ 0.66701673, 0.33298327],
[ 0.83970087, 0.16029913],
[ 0.84390822, 0.15609178],
[ 0.68848223, 0.31151777],
[ 0.71783503, 0.28216497],
[ 0.44774958, 0.55225042],
[ 0.52428795, 0.47571205],
[ 0.42239925, 0.57760075],
[ 0.40707987, 0.59292013],
[ 0.26241217, 0.73758783],
[ 0.75435635, 0.24564365],
[ 0.76041059, 0.23958941],
[ 0.1751494 , 0.8248506 ],
[ 0.2115111 , 0.7884889 ],
[ 0.33498929, 0.66501071],
[ 0.5563039 , 0.4436961 ],
[ 0.5702084 , 0.4297916 ],
[ 0.81746059, 0.18253941],
[ 0.73049817, 0.26950183],
[ 0.82725613, 0.17274387],
[ 0.2892864 , 0.7107136 ],
[ 0.08020346, 0.91979654],
[ 0.53995019, 0.46004981],
[ 0.76699566, 0.23300434],
[ 0.21584237, 0.78415763],
[ 0.7839562 , 0.2160438 ],
[ 0.26331428, 0.73668572],
[ 0.06349098, 0.93650902],
[ 0.37812357, 0.62187643],
[ 0.467999 , 0.532001 ],
[ 0.75328223, 0.24671777],
[ 0.60988451, 0.39011549],
[ 0.17355685, 0.82644315],
[ 0.32794276, 0.67205724],
[ 0.62194676, 0.37805324],
[ 0.56737758, 0.43262242],
[ 0.13106675, 0.86893325],
[ 0.13607513, 0.86392487]])
In [35]:
softmax_b.sum(axis=1)
Out[35]:
array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1.])
In [ ]:
Content source: ml6973/Course
Similar notebooks: