Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions Matrix multiplication.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def nm(big,small):\n",
" len_row= big.shape[0]-small.shape[0]+1\n",
" len_col= big.shape[1]-small.shape[1]+1\n",
" new = np.zeros((len_row,len_col))\n",
" \n",
" \n",
" count_col = 0\n",
" count_row = 0\n",
"\n",
" mu= np.zeros((small.shape))\n",
" \n",
" for count_col in range(len_col):\n",
" for count_row in range(len_row):\n",
" for ix in range(small.shape[0]):\n",
" for jx in range(small.shape[1]):\n",
" mu[ix][jx]=small[ix][jx]*big[count_row+ix][count_col+jx]\n",
" yeah = mu.sum()\n",
" new[count_row][count_col]=yeah\n",
" yeah = 0\n",
" mu[:]=0\n",
" \n",
" return new\n",
" \n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(3, 3)\n",
"(2, 2)\n",
"[[19. 32.]\n",
" [34. 34.]]\n"
]
}
],
"source": [
"big = np.array([(5,3,7),(2,4,7),(9,6,4)])\n",
"print (big.shape)\n",
"small = np.array([(1,2),(2,1)])\n",
"print (small.shape)\n",
"ans = nm(big,small)\n",
"print (ans)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}