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
98 changes: 98 additions & 0 deletions homework_tanuj.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt \n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [],
"source": [
"def Multiply(matrix1,matrix2):\n",
" \n",
" factor1 = matrix1.shape[0]\n",
" factor2 = matrix2.shape[1]\n",
"\n",
" count = factor1-factor2+1\n",
" matrix3 = np.zeros((factor2,factor2))\n",
" matrix4 = np.zeros((count,count))\n",
"\n",
" for i in range(count):\n",
" for j in range (count):\n",
" matrix3[:,:] = matrix1[j:factor2+j,i:factor2+i]\n",
" \n",
" flag = 0\n",
" for k in range(factor2):\n",
" for l in range (factor2):\n",
" flag+=matrix3[k][l]*matrix2[k][l]\n",
" \n",
" matrix4[j][i]=flag\n",
" return matrix4\n",
" \n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[28. 15.]\n",
" [23. 21.]]\n"
]
}
],
"source": [
"matrix1 = np.array(([2,3,1],[4,2,1],[1,3,2]))\n",
"matrix2 = np.array(([1,2],[3,4]))\n",
"\n",
"print Multiply(matrix1,matrix2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
")\n"
]
}
],
"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
}