Softmax NumPy implementation

Hi all

I am trying to implement the softmax equation as,

def my_softmax(z):

N = len(z)
a = 0
ez_sum = 0
ez = np.exp(z)

for k in range(N):
    ez_sum = ez_sum + np.sum(ez[k])
for j in range(N):
    a[j] = ez[j] / ez_sum
    a = a[j]
return a

however, I am receiving the following error:

Any help in solving the issue in line 21 would be appreciated!

You really don’t need to use any for-loops for this.
That would avoid the indexing complexity.

I tried avoiding the for loops, however, despite of obtaining correct values at the output, an error for the wrong values at the output was appeared. This is why I used for loops again.

You are getting the error because of the line a = 0, and later addressing “a” with an index

Thanks, I solved the issue!