Python function for finding softmax output of a vector


Topic: Python function for finding softmax output of a vector

Solution

def softmax(x):
  """returns the softmax output of a vector"""
  if(type(x) == int or type(x) == float):
    return 1
  denom = 0
  for i in x:
    denom+=math.exp(i)
  new_vec = []
  for i in x:
    new_vec.append(math.exp(i)/denom)
  return new_vec
  



List all Python Programs