Numpy Pandas

parent 512a5eb6
......@@ -868,7 +868,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 5,
"metadata": {},
"outputs": [
{
......@@ -902,9 +902,19 @@
"#Tarea, generar el producto punto\n",
"def prod_punto(v1,v2):\n",
" '''\n",
" Soy un docstring\n",
" Función que calcula el producto punto entre dos vectores de tamaño n\n",
" \n",
" Args:\n",
" v1 (vector): Lista vacia\n",
" v2 (vector): Lista vacia\n",
" \n",
" Yields:\n",
" \n",
" Examples:\n",
" >>> prod_punto([10,20],[2,4])\n",
" '100'\n",
" '''\n",
" v1,v2,v3=[],[],[]\n",
" v3=[]\n",
" elementos=int(input(\"Cuantos elementos tienen tus vectores: \\n\"))\n",
" \n",
" print(\"Ingresa los elementos uno a uno del vector 1 \\n\")\n",
......@@ -922,29 +932,12 @@
" \n",
" print(\"\\nVector 1: \"+str(v1)+\"\\n\"+\"Vector 2: \"+str(v2)+\"\\n\"+\"Suma Producto: \"+str(sumap))\n",
" return sumap\n",
"\n",
" #return prod_punto\n",
"x=prod_punto(3,4)"
]
},
{
"cell_type": "code",
"execution_count": 162,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"100"
]
},
"execution_count": 162,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Comprobacion con Numpy\n",
"np.matmul([10,20], [2,4])"
" \n",
"vector1=[]\n",
"vector2=[]\n",
"x=prod_punto(vector1,vector2)"
]
},
{
......@@ -1024,21 +1017,11 @@
"'''\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",
"print(m, type(m))\n",
"### m = np.array([[sum(row_a*col_b) for col_b in b.T] for row_a in a])\n",
"### print(m, type(m))\n",
"###"
]
},
{
"cell_type": "code",
"execution_count": 212,
"metadata": {},
"outputs": [],
"source": [
"a=np.array(mat1)\n",
"b=np.array(mat2)\n"
]
},
{
"cell_type": "code",
"execution_count": 118,
......@@ -1162,28 +1145,6 @@
"mmult1(mat1,mat2)"
]
},
{
"cell_type": "code",
"execution_count": 206,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[220, 280],\n",
" [490, 640]])"
]
},
"execution_count": 206,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Comprobacion con Numpy\n",
"np.matmul(mat1, mat2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -1193,21 +1154,27 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 206,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[]"
"array([[220, 280],\n",
" [490, 640]])"
]
},
"execution_count": 23,
"execution_count": 206,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
"source": [
"#Comprobacion con Numpy ejercicio 1\n",
"np.matmul([10,20], [2,4])\n",
"#Comprobacion con Numpy ejercicio 2\n",
"np.matmul(mat1, mat2)"
]
},
{
"cell_type": "markdown",
......@@ -1225,11 +1192,12 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": []
"source": [
"((trans(A)*A)^-1)*trans(A)\n",
"Nota: Utilizar arreglos de Numpy\n"
]
},
{
"cell_type": "markdown",
......@@ -1249,7 +1217,7 @@
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
......@@ -1259,21 +1227,21 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a 0.994272\n",
"b 0.530519\n",
"c 1.162452\n",
"d -0.981436\n",
"e -1.283798\n",
"a -1.021430\n",
"b -0.479428\n",
"c -0.038148\n",
"d 0.998008\n",
"e 1.063352\n",
"dtype: float64"
]
},
"execution_count": 51,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1285,21 +1253,21 @@
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 2.042498\n",
"1 -0.964070\n",
"2 -0.687132\n",
"3 0.623300\n",
"4 1.366322\n",
"0 1.071136\n",
"1 1.001901\n",
"2 0.094653\n",
"3 -0.492713\n",
"4 0.829835\n",
"dtype: float64"
]
},
"execution_count": 46,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1310,7 +1278,7 @@
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": 9,
"metadata": {},
"outputs": [
{
......@@ -1322,7 +1290,7 @@
"dtype: int64"
]
},
"execution_count": 47,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1334,7 +1302,7 @@
},
{
"cell_type": "code",
"execution_count": 48,
"execution_count": 10,
"metadata": {},
"outputs": [
{
......@@ -1347,7 +1315,7 @@
"dtype: float64"
]
},
"execution_count": 48,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1366,16 +1334,16 @@
},
{
"cell_type": "code",
"execution_count": 53,
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.9942721192063438"
"-1.0214304735714077"
]
},
"execution_count": 53,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1386,19 +1354,19 @@
},
{
"cell_type": "code",
"execution_count": 54,
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a 0.994272\n",
"b 0.530519\n",
"c 1.162452\n",
"a -1.021430\n",
"b -0.479428\n",
"c -0.038148\n",
"dtype: float64"
]
},
"execution_count": 54,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1409,19 +1377,18 @@
},
{
"cell_type": "code",
"execution_count": 55,
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a 0.994272\n",
"b 0.530519\n",
"c 1.162452\n",
"d 0.998008\n",
"e 1.063352\n",
"dtype: float64"
]
},
"execution_count": 55,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1432,21 +1399,26 @@
},
{
"cell_type": "code",
"execution_count": 56,
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a 1.988544\n",
"b 1.061037\n",
"c 2.324904\n",
"d -1.962872\n",
"e -2.567597\n",
"dtype: float64"
"0 0\n",
"1 2\n",
"2 4\n",
"3 6\n",
"4 8\n",
"5 10\n",
"6 12\n",
"7 14\n",
"8 16\n",
"9 18\n",
"dtype: int64"
]
},
"execution_count": 56,
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1457,21 +1429,26 @@
},
{
"cell_type": "code",
"execution_count": 57,
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a True\n",
"b False\n",
"c True\n",
"d False\n",
"e False\n",
"0 False\n",
"1 False\n",
"2 False\n",
"3 False\n",
"4 False\n",
"5 True\n",
"6 True\n",
"7 True\n",
"8 True\n",
"9 True\n",
"dtype: bool"
]
},
"execution_count": 57,
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1482,16 +1459,16 @@
},
{
"cell_type": "code",
"execution_count": 58,
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.9942721192063438"
"-1.0214304735714077"
]
},
"execution_count": 58,
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1509,7 +1486,7 @@
},
{
"cell_type": "code",
"execution_count": 59,
"execution_count": 44,
"metadata": {},
"outputs": [],
"source": [
......@@ -1519,7 +1496,7 @@
},
{
"cell_type": "code",
"execution_count": 60,
"execution_count": 41,
"metadata": {},
"outputs": [
{
......@@ -1528,7 +1505,7 @@
"array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
]
},
"execution_count": 60,
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1539,7 +1516,7 @@
},
{
"cell_type": "code",
"execution_count": 62,
"execution_count": 42,
"metadata": {},
"outputs": [
{
......@@ -1558,7 +1535,7 @@
"dtype: int64"
]
},
"execution_count": 62,
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1614,15 +1591,9 @@
}
],
"source": [
"#En series la suma es elemento a elemento poer con respecto al índice de toda la variable\n",
"(s[:6]+s[4:])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
......
......@@ -868,7 +868,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 5,
"metadata": {},
"outputs": [
{
......@@ -902,9 +902,19 @@
"#Tarea, generar el producto punto\n",
"def prod_punto(v1,v2):\n",
" '''\n",
" Soy un docstring\n",
" Función que calcula el producto punto entre dos vectores de tamaño n\n",
" \n",
" Args:\n",
" v1 (vector): Lista vacia\n",
" v2 (vector): Lista vacia\n",
" \n",
" Yields:\n",
" \n",
" Examples:\n",
" >>> prod_punto([10,20],[2,4])\n",
" '100'\n",
" '''\n",
" v1,v2,v3=[],[],[]\n",
" v3=[]\n",
" elementos=int(input(\"Cuantos elementos tienen tus vectores: \\n\"))\n",
" \n",
" print(\"Ingresa los elementos uno a uno del vector 1 \\n\")\n",
......@@ -922,29 +932,12 @@
" \n",
" print(\"\\nVector 1: \"+str(v1)+\"\\n\"+\"Vector 2: \"+str(v2)+\"\\n\"+\"Suma Producto: \"+str(sumap))\n",
" return sumap\n",
"\n",
" #return prod_punto\n",
"x=prod_punto(3,4)"
]
},
{
"cell_type": "code",
"execution_count": 162,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"100"
]
},
"execution_count": 162,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Comprobacion con Numpy\n",
"np.matmul([10,20], [2,4])"
" \n",
"vector1=[]\n",
"vector2=[]\n",
"x=prod_punto(vector1,vector2)"
]
},
{
......@@ -1024,21 +1017,11 @@
"'''\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",
"print(m, type(m))\n",
"### m = np.array([[sum(row_a*col_b) for col_b in b.T] for row_a in a])\n",
"### print(m, type(m))\n",
"###"
]
},
{
"cell_type": "code",
"execution_count": 212,
"metadata": {},
"outputs": [],
"source": [
"a=np.array(mat1)\n",
"b=np.array(mat2)\n"
]
},
{
"cell_type": "code",
"execution_count": 118,
......@@ -1162,28 +1145,6 @@
"mmult1(mat1,mat2)"
]
},
{
"cell_type": "code",
"execution_count": 206,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[220, 280],\n",
" [490, 640]])"
]
},
"execution_count": 206,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Comprobacion con Numpy\n",
"np.matmul(mat1, mat2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -1193,21 +1154,27 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 206,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[]"
"array([[220, 280],\n",
" [490, 640]])"
]
},
"execution_count": 23,
"execution_count": 206,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
"source": [
"#Comprobacion con Numpy ejercicio 1\n",
"np.matmul([10,20], [2,4])\n",
"#Comprobacion con Numpy ejercicio 2\n",
"np.matmul(mat1, mat2)"
]
},
{
"cell_type": "markdown",
......@@ -1225,11 +1192,12 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": []
"source": [
"((trans(A)*A)^-1)*trans(A)\n",
"Nota: Utilizar arreglos de Numpy\n"
]
},
{
"cell_type": "markdown",
......@@ -1249,7 +1217,7 @@
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
......@@ -1259,21 +1227,21 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a 0.994272\n",
"b 0.530519\n",
"c 1.162452\n",
"d -0.981436\n",
"e -1.283798\n",
"a -1.021430\n",
"b -0.479428\n",
"c -0.038148\n",
"d 0.998008\n",
"e 1.063352\n",
"dtype: float64"
]
},
"execution_count": 51,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1285,21 +1253,21 @@
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 2.042498\n",
"1 -0.964070\n",
"2 -0.687132\n",
"3 0.623300\n",
"4 1.366322\n",
"0 1.071136\n",
"1 1.001901\n",
"2 0.094653\n",
"3 -0.492713\n",
"4 0.829835\n",
"dtype: float64"
]
},
"execution_count": 46,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1310,7 +1278,7 @@
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": 9,
"metadata": {},
"outputs": [
{
......@@ -1322,7 +1290,7 @@
"dtype: int64"
]
},
"execution_count": 47,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1334,7 +1302,7 @@
},
{
"cell_type": "code",
"execution_count": 48,
"execution_count": 10,
"metadata": {},
"outputs": [
{
......@@ -1347,7 +1315,7 @@
"dtype: float64"
]
},
"execution_count": 48,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1366,16 +1334,16 @@
},
{
"cell_type": "code",
"execution_count": 53,
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.9942721192063438"
"-1.0214304735714077"
]
},
"execution_count": 53,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1386,19 +1354,19 @@
},
{
"cell_type": "code",
"execution_count": 54,
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a 0.994272\n",
"b 0.530519\n",
"c 1.162452\n",
"a -1.021430\n",
"b -0.479428\n",
"c -0.038148\n",
"dtype: float64"
]
},
"execution_count": 54,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1409,19 +1377,18 @@
},
{
"cell_type": "code",
"execution_count": 55,
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a 0.994272\n",
"b 0.530519\n",
"c 1.162452\n",
"d 0.998008\n",
"e 1.063352\n",
"dtype: float64"
]
},
"execution_count": 55,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1432,21 +1399,26 @@
},
{
"cell_type": "code",
"execution_count": 56,
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a 1.988544\n",
"b 1.061037\n",
"c 2.324904\n",
"d -1.962872\n",
"e -2.567597\n",
"dtype: float64"
"0 0\n",
"1 2\n",
"2 4\n",
"3 6\n",
"4 8\n",
"5 10\n",
"6 12\n",
"7 14\n",
"8 16\n",
"9 18\n",
"dtype: int64"
]
},
"execution_count": 56,
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1457,21 +1429,26 @@
},
{
"cell_type": "code",
"execution_count": 57,
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a True\n",
"b False\n",
"c True\n",
"d False\n",
"e False\n",
"0 False\n",
"1 False\n",
"2 False\n",
"3 False\n",
"4 False\n",
"5 True\n",
"6 True\n",
"7 True\n",
"8 True\n",
"9 True\n",
"dtype: bool"
]
},
"execution_count": 57,
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1482,16 +1459,16 @@
},
{
"cell_type": "code",
"execution_count": 58,
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.9942721192063438"
"-1.0214304735714077"
]
},
"execution_count": 58,
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1509,7 +1486,7 @@
},
{
"cell_type": "code",
"execution_count": 59,
"execution_count": 44,
"metadata": {},
"outputs": [],
"source": [
......@@ -1519,7 +1496,7 @@
},
{
"cell_type": "code",
"execution_count": 60,
"execution_count": 41,
"metadata": {},
"outputs": [
{
......@@ -1528,7 +1505,7 @@
"array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
]
},
"execution_count": 60,
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1539,7 +1516,7 @@
},
{
"cell_type": "code",
"execution_count": 62,
"execution_count": 42,
"metadata": {},
"outputs": [
{
......@@ -1558,7 +1535,7 @@
"dtype: int64"
]
},
"execution_count": 62,
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1614,15 +1591,9 @@
}
],
"source": [
"#En series la suma es elemento a elemento poer con respecto al índice de toda la variable\n",
"(s[:6]+s[4:])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
......
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