"'def matmult(a,b):\\n zip_b = zip(*b)\\n #uncomment next line if python 3 : \\n zip_b = list(zip_b)\\n return [[sum(ele_a*ele_b for ele_a, ele_b in zip(row_a, col_b)) \\n for col_b in zip_b] for row_a in a]\\n'"
]
},
"execution_count": 173,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def tamMatriz():\n",
" n=int(input(\"Ingrese las filas de la matriz: \\n\"))\n",
" m=int(input(\"Ingrese las columnas de la matriz: \\n\"))\n",
" return [n,m]\n",
"\n",
"def creaMatriz(nFila, nCol):\n",
" matriz = []\n",
" for i in range(nFila):\n",
" listaFila = []\n",
" for j in range(nCol):\n",
" val=int(input(\"Ingresa el valor del elemento\"+str(i)+\",\"+str(j)+\": \\n\"))\n",
" listaFila.append(val)\n",
" matriz.append(listaFila)\n",
"\n",
" return matriz\n",
"\n",
"def mmult1(m1, m2):\n",
" fila_A = len(m1)\n",
" cols_A = len(m1[0])\n",
" fila_B = len(m2)\n",
" cols_B = len(m2[0])\n",
"\n",
" if cols_A != fila_B:\n",
" print (\"Imposible resolver, la dimensionalidad de las matrices no cuadra.\")\n",
" return\n",
"\n",
" C = [[0 for fila in range(cols_B)] for col in range(fila_A)]\n",
" print (C)\n",
"\n",
" for i in range(fila_A):\n",
" for j in range(cols_B):\n",
" for k in range(cols_A):\n",
" C[i][j] += m1[i][k] * m2[k][j]\n",
" return C\n",
"\n",
"#Me encantaria que me podieran explicar esta ya que es extremadamente eficiente :O\n",
"\n",
"'''def matmult(a,b):\n",
" zip_b = zip(*b)\n",
" #uncomment next line if python 3 : \n",
" zip_b = list(zip_b)\n",
" return [[sum(ele_a*ele_b for ele_a, ele_b in zip(row_a, col_b)) \n",
" for col_b in zip_b] for row_a in a]\n",
"'''\n",
"\n",
"'''b=mat2\n",
"print(b)\n",
"zip_b = zip(*b)\n",
"for col_b in zip_b:\n",
" print(col_b)\n",
"'''\n",
"\n",
"### Muy PRO\n",
"m = np.array([[sum(row_a*col_b) for col_b in b.T] for row_a in a])\n",
"'def matmult(a,b):\\n zip_b = zip(*b)\\n #uncomment next line if python 3 : \\n zip_b = list(zip_b)\\n return [[sum(ele_a*ele_b for ele_a, ele_b in zip(row_a, col_b)) \\n for col_b in zip_b] for row_a in a]\\n'"
]
},
"execution_count": 173,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def tamMatriz():\n",
" n=int(input(\"Ingrese las filas de la matriz: \\n\"))\n",
" m=int(input(\"Ingrese las columnas de la matriz: \\n\"))\n",
" return [n,m]\n",
"\n",
"def creaMatriz(nFila, nCol):\n",
" matriz = []\n",
" for i in range(nFila):\n",
" listaFila = []\n",
" for j in range(nCol):\n",
" val=int(input(\"Ingresa el valor del elemento\"+str(i)+\",\"+str(j)+\": \\n\"))\n",
" listaFila.append(val)\n",
" matriz.append(listaFila)\n",
"\n",
" return matriz\n",
"\n",
"def mmult1(m1, m2):\n",
" fila_A = len(m1)\n",
" cols_A = len(m1[0])\n",
" fila_B = len(m2)\n",
" cols_B = len(m2[0])\n",
"\n",
" if cols_A != fila_B:\n",
" print (\"Imposible resolver, la dimensionalidad de las matrices no cuadra.\")\n",
" return\n",
"\n",
" C = [[0 for fila in range(cols_B)] for col in range(fila_A)]\n",
" print (C)\n",
"\n",
" for i in range(fila_A):\n",
" for j in range(cols_B):\n",
" for k in range(cols_A):\n",
" C[i][j] += m1[i][k] * m2[k][j]\n",
" return C\n",
"\n",
"#Me encantaria que me podieran explicar esta ya que es extremadamente eficiente :O\n",
"\n",
"'''def matmult(a,b):\n",
" zip_b = zip(*b)\n",
" #uncomment next line if python 3 : \n",
" zip_b = list(zip_b)\n",
" return [[sum(ele_a*ele_b for ele_a, ele_b in zip(row_a, col_b)) \n",
" for col_b in zip_b] for row_a in a]\n",
"'''\n",
"\n",
"'''b=mat2\n",
"print(b)\n",
"zip_b = zip(*b)\n",
"for col_b in zip_b:\n",
" print(col_b)\n",
"'''\n",
"\n",
"### Muy PRO\n",
"m = np.array([[sum(row_a*col_b) for col_b in b.T] for row_a in a])\n",