softmax c 2b 2b

Solutions on MaxInterview for softmax c 2b 2b by the best coders in the world

showing results for - "softmax c 2b 2b"
María Alejandra
31 Jun 2020
1// this function calculates the the softmax function.
2// @param size is the size of the input vector.
3// @param z is the input vector.
4// @return buff is the output vector.
5double* softmax(const int size, double* z)
6{
7  double* buff = new double[size];
8  double sum = 0;
9  for (int i = 0; i < size; i++)
10    sum += Exp(z[i]);
11
12  for (int i = 0; i < size; i++)
13    buff[i] = Exp(z[i]) / sum;
14  
15  return buff;
16}