Softmax operator. Parameters ---------- a_np : numpy.ndarray N-D input data Returns ------- output_np : numpy.ndarray N-D output with same shape
(a_np, axis=1)
| 21 | |
| 22 | |
| 23 | def softmax_python(a_np, axis=1): |
| 24 | """Softmax operator. |
| 25 | Parameters |
| 26 | ---------- |
| 27 | a_np : numpy.ndarray |
| 28 | N-D input data |
| 29 | |
| 30 | Returns |
| 31 | ------- |
| 32 | output_np : numpy.ndarray |
| 33 | N-D output with same shape |
| 34 | """ |
| 35 | max_elem = np.amax(a_np, axis=axis, keepdims=True) |
| 36 | e = np.exp(a_np - max_elem) |
| 37 | expsum = np.sum(e, axis=axis, keepdims=True) |
| 38 | out_np = e / expsum |
| 39 | return out_np |
| 40 | |
| 41 | |
| 42 | def log_softmax_python(a_np, axis=1): |
no test coverage detected
searching dependent graphs…