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
78 changes: 78 additions & 0 deletions matrix_multiplication.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
"## defined for only square matrices\n",
"\n",
"def matrix_multiplication(small_array,large_array):\n",
" mat=np.zeros([large_array.shape[0]-small_array.shape[0]+1,large_array.shape[1]-small_array.shape[1]+1])\n",
" for ix in range(large_array.shape[1]-small_array.shape[1]+1):\n",
" for jx in range(large_array.shape[0]-small_array.shape[0]+1):\n",
" split=large_array[ix:ix+small_array.shape[0],jx:jx+small_array.shape[1]]\n",
" mat[ix,jx]=np.sum(small_array*split)\n",
" return mat"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[318. 360.]\n",
" [486. 528.]]\n"
]
}
],
"source": [
"large_array=np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])\n",
"small_array=np.array([[1,2,3],[4,5,6],[6,7,8]])\n",
"print matrix_multiplication(small_array,large_array)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}