Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

softmax is not working: i have syntax error somewhere

I’m trying to reach this command:

sm(x=[3,4,1])=[0.259,0.705,0.036]

However I’m getting an error. Apparently I have a wrong syntax:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

A NON-PICTURE RESULTS A minimal reproducible example is this:

import statsmodels.api as sm
sm([1,2,-4])

--------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[39], line 2
      1 import statsmodels.api as sm
----> 2 sm([1,2,-4])

TypeError: 'module' object is not callable

>Solution :

Solution:

You can use the scipy package to calculate softmax as follows.

import numpy as np
from scipy.special import softmax

x=[3,4,1]
m = softmax(x)
print(m)

# [0.25949646 0.70538451 0.03511903]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading