So in this simple code the line
result[columnNumber] = column #this assignment fails for some reason!
fails, and specifically it simply assigns array of zeroes instead of what it is supposed to assign, and I have no idea why! So this is the full code:
"""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."""
data=np.array(x)
columnNumber=0
result=data.copy()
result=result.T
for column in data.T:
sumCurrentColumn=0
try: #Since 'column' can potentially be just a double,and sum needs some iterable object
sumCurrentColumn=sum(np.exp(column))
except TypeError:
sumCurrentColumn=np.exp(column)
column=np.divide(np.exp(column),sumCurrentColumn)
print(column)
print('before assignment:'+str(result[columnNumber]))
result[columnNumber] = column #this assignment fails for some reason!
print('after assignment:'+str(result[columnNumber]))
columnNumber+=1
result=result.T
return result
scores = np.array([[1, 2, 3, 6],
[2, 4, 5, 6],
[3, 8, 7, 6]])
print(softmax(scores))
and this is its output:
[ 0.09003057 0.24472847 0.66524096]
before assignment:[1 2 3]
after assignment:[0 0 0]
[ 0.00242826 0.01794253 0.97962921]
before assignment:[2 4 8]
after assignment:[0 0 0]
[ 0.01587624 0.11731043 0.86681333]
before assignment:[3 5 7]
after assignment:[0 0 0]
[ 0.33333333 0.33333333 0.33333333]
before assignment:[6 6 6]
after assignment:[0 0 0]
[[0 0 0 0]
[0 0 0 0]
[0 0 0 0]]