Improved implementation of softmax_cols()

This commit is contained in:
udlbook
2024-04-15 16:01:38 -04:00
parent e8fca0cb0a
commit d17e47421b

View File

@@ -4,7 +4,6 @@
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyMSk8qTqDYqFnRJVZKlsue0",
"include_colab_link": true
},
"kernelspec": {
@@ -147,9 +146,7 @@
" exp_values = np.exp(data_in) ;\n",
" # Sum over columns\n",
" denom = np.sum(exp_values, axis = 0);\n",
" # Replicate denominator to N rows\n",
" denom = np.matmul(np.ones((data_in.shape[0],1)), denom[np.newaxis,:])\n",
" # Compute softmax\n",
" # Compute softmax (numpy broadcasts denominator to all rows automatically)\n",
" softmax = exp_values / denom\n",
" # return the answer\n",
" return softmax"