this script demonstrates the implementation of the softmax function its a function that takes as input a vector of k real numbers and normalizes it into a probability distribution consisting of k probabilities proportional to the exponentials of the input numbers after softmax the elements of the vector always sum up to 1 script inspired from its corresponding wikipedia article https en wikipedia orgwikisoftmaxfunction implements the softmax function parameters vector np array list tuple a numpy array of shape 1 n consisting of real values or a similar list tuple returns softmaxvec np array the input numpy array after applying softmax the softmax vector adds up to one we need to ceil to mitigate for precision np ceilnp sumsoftmax1 2 3 4 1 0 vec np array5 5 softmaxvec array0 5 0 5 softmax0 array1 calculate ex for each x in your vector where e is euler s number approximately 2 718 add up the all the exponentials divide every exponent by the sum of all exponents implements the softmax function parameters vector np array list tuple a numpy array of shape 1 n consisting of real values or a similar list tuple returns softmax_vec np array the input numpy array after applying softmax the softmax vector adds up to one we need to ceil to mitigate for precision np ceil np sum softmax 1 2 3 4 1 0 vec np array 5 5 softmax vec array 0 5 0 5 softmax 0 array 1 calculate e x for each x in your vector where e is euler s number approximately 2 718 add up the all the exponentials divide every exponent by the sum of all exponents
import numpy as np


def softmax(vector):
    

    
    
    exponent_vector = np.exp(vector)

    
    sum_of_exponents = np.sum(exponent_vector)

    
    softmax_vector = exponent_vector / sum_of_exponents

    return softmax_vector


if __name__ == "__main__":
    print(softmax((0,)))