softmax implementation c+ code example
Example: softmax c++
// this function calculates the the softmax function.
// @param size is the size of the input vector.
// @param z is the input vector.
// @return buff is the output vector.
double* softmax(const int size, double* z)
{
double* buff = new double[size];
double sum = 0;
for (int i = 0; i < size; i++)
sum += Exp(z[i]);
for (int i = 0; i < size; i++)
buff[i] = Exp(z[i]) / sum;
return buff;
}