commit e73bbe68068fc543da8bdb0953cd5051b4d9fb63
parent e9171b0c875e25f7caa2aa45a6eb938963ff9744
Author: Andrew <andrewlaack1@gmail.com>
Date: Thu, 14 Nov 2024 20:16:32 -0600
revised mat mul
Diffstat:
1 file changed, 32 insertions(+), 6 deletions(-)
diff --git a/nnFromScratch/matMul(DP).ipynb b/nnFromScratch/matMul(DP).ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 169,
"metadata": {},
"outputs": [],
"source": [
@@ -24,17 +24,17 @@
"\n",
"# mat mul\n",
"def naiveMatMul(x,y):\n",
- " ret = np.zeros(shape=(len(x), len(y)))\n",
+ " ret = np.zeros(shape=(len(x), len(y[0])))\n",
"\n",
" for z in range(0,len(x)):\n",
- " for i in range(0, len(y)):\n",
+ " for i in range(0, len(y[0])):\n",
" ret[z][i] = naiveVectorDotProduct(x[z], y[:,i])\n",
" return ret"
]
},
{
"cell_type": "code",
- "execution_count": 92,
+ "execution_count": 170,
"metadata": {},
"outputs": [
{
@@ -55,7 +55,7 @@
},
{
"cell_type": "code",
- "execution_count": 83,
+ "execution_count": 171,
"metadata": {},
"outputs": [
{
@@ -81,7 +81,7 @@
},
{
"cell_type": "code",
- "execution_count": 91,
+ "execution_count": 172,
"metadata": {},
"outputs": [
{
@@ -112,6 +112,32 @@
"print(\"First: \\n\" + str(X@y))\n",
"print(\"Second: \\n\" + str(naiveMatMul(X,y)))"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 190,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "True"
+ ]
+ },
+ "execution_count": 190,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "x = np.random.random((5,30))\n",
+ "y = np.random.random((30,2))\n",
+ "\n",
+ "prod = (x @ y).astype(np.uint)\n",
+ "product = naiveMatMul(x,y).astype(np.uint)\n",
+ "res = product == prod\n",
+ "res.all()"
+ ]
}
],
"metadata": {