Commit 7ef96275 authored by geobumac's avatar geobumac

practicas

parent 9163d496
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -173,12 +173,23 @@ ...@@ -173,12 +173,23 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[20 30 40 50]\n",
"[0 1 2 3]\n"
]
}
],
"source": [ "source": [
"a = np.array([20,30,40,50] )\n", "a = np.array([20,30,40,50] )\n",
"b = np.arange( 4 )" "b = np.arange( 4 )\n",
"print(a)\n",
"print(b)"
] ]
}, },
{ {
...@@ -761,12 +772,25 @@ ...@@ -761,12 +772,25 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 36, "execution_count": 17,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"166.39999999999998\n"
]
}
],
"source": [ "source": [
"def getProdPunto(a,b):\n",
" return sum([i*b[idx] for idx,i in enumerate(a)])\n",
"\n",
"a = [2, 5.6, 9, 8, 10]\n", "a = [2, 5.6, 9, 8, 10]\n",
"b = [1, 3, 2.4, 2, 11]" "b = [1, 3, 2.4, 2, 11] \n",
"prductopunto = getProdPunto(a,b)\n",
"print(prductopunto)\n"
] ]
}, },
{ {
...@@ -778,12 +802,54 @@ ...@@ -778,12 +802,54 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 37, "execution_count": 23,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 7 7\n",
"2 9 18\n",
"3 11 33\n",
"------ 58\n",
"1 8 8\n",
"2 10 20\n",
"3 12 36\n",
"------ 64\n",
"4 7 28\n",
"5 9 45\n",
"6 11 66\n",
"------ 139\n",
"4 8 32\n",
"5 10 50\n",
"6 12 72\n",
"------ 154\n",
"[[58, 64], [139, 154]]\n"
]
}
],
"source": [ "source": [
"def getProdMat(A,B):\n",
" prodmat = []\n",
" if(len(A) == len(B[0])):\n",
" for indiceA, elemA in enumerate(A):\n",
" elemProdMat = []\n",
" for cont in range(len(A)):\n",
" auxSuma = 0\n",
" for subIndiceA, subElemA in enumerate(elemA):\n",
" auxSuma += subElemA*B[subIndiceA][cont]\n",
" print(subElemA, \" \", B[subIndiceA][cont], \" \", subElemA*B[subIndiceA][cont])\n",
" elemProdMat.append(auxSuma)\n",
" print(\"------\", auxSuma)\n",
" prodmat.append(elemProdMat)\n",
" return prodmat\n",
" else:\n",
" return \"La matriz debe ser A=mxn y B=nxp\"\n",
" \n",
"A = [[1,2,3],[4,5,6]]\n", "A = [[1,2,3],[4,5,6]]\n",
"B = [[7,8],[9,10],[11,12]]" "B = [[7,8],[9,10],[11,12]]\n",
"print(getProdMat(A,B))"
] ]
}, },
{ {
...@@ -795,10 +861,28 @@ ...@@ -795,10 +861,28 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 15,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
"source": [] {
"name": "stdout",
"output_type": "stream",
"text": [
"166.39999999999998\n",
"[[ 58 64]\n",
" [139 154]]\n"
]
}
],
"source": [
"import numpy as np\n",
"a = np.array([2, 5.6, 9, 8, 10])\n",
"b = np.array([1, 3, 2.4, 2, 11])\n",
"print(a.dot(b))\n",
"a = np.array([[1,2,3],[4,5,6]])\n",
"b = np.array([[7,8],[9,10],[11,12]])\n",
"print(np.matmul(a,b))"
]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
...@@ -1232,7 +1316,7 @@ ...@@ -1232,7 +1316,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.3" "version": "3.6.7"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment