Aktualizacja materiałów do laboratoriów 1

This commit is contained in:
Paweł Skórzewski 2023-03-02 11:09:27 +01:00
parent d81fefa352
commit e481384b66

View File

@ -35,7 +35,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"outputs": [
{
@ -78,8 +78,7 @@
],
"source": [
"zdanie = \"tracz tarł tarcicę tak takt w takt jak takt w takt tarcicę tartak tarł\"\n",
"wyrazy = zdanie.split()\n",
"dlugosci_wyrazow = [len(wyraz) for wyraz in wyrazy]\n",
"dlugosci_wyrazow = [len(wyraz) for wyraz in zdanie.split()]\n",
"\n",
"print(dlugosci_wyrazow)\n"
]
@ -134,6 +133,25 @@
"Wszystkie listy i krotki w Pythonie, w tym łańcuchy (które trakowane są jak krotki znaków), są indeksowane od 0:"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[4, 16, 36, 64, 100]\n",
"[4, 16, 36, 64, 100]\n"
]
}
],
"source": [
"print(lista)\n",
"print(lista[:])"
]
},
{
"cell_type": "code",
"execution_count": 11,
@ -255,7 +273,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 20,
"metadata": {},
"outputs": [
{
@ -264,14 +282,15 @@
"text": [
"[[1 2 3]\n",
" [4 5 6]\n",
" [7 8 9]]\n"
" [7 8 9]\n",
" [2 5 8]]\n"
]
}
],
"source": [
"import numpy as np\n",
"\n",
"x = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])\n",
"x = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [2, 5, 8]])\n",
"print(x)\n"
]
},
@ -284,62 +303,55 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3, 3)"
"name": "stdout",
"output_type": "stream",
"text": [
"(4, 3)\n"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x.shape\n"
"print(x.shape) # wymiary macierzy\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([12, 15, 18])"
"name": "stdout",
"output_type": "stream",
"text": [
"[14 20 26]\n",
"[ 6 15 24 15]\n"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x.sum(axis=0)\n"
"print(x.sum(axis=0)) # suma liczb w każdej kolumnie\n",
"print(x.sum(axis=1)) # suma liczb w każdym wierszu"
]
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([2., 5., 8.])"
"name": "stdout",
"output_type": "stream",
"text": [
"[2. 5. 8. 5.]\n"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x.mean(axis=1)\n"
"print(x.mean(axis=1)) # średnia liczb w każdym wierszu\n"
]
},
{
@ -450,19 +462,19 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 32,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0. 1.25 2.5 3.75 5. ]\n"
"[0. 0.625 1.25 1.875 2.5 3.125 3.75 4.375 5. ]\n"
]
}
],
"source": [
"x = np.linspace(0, 5, 5)\n",
"x = np.linspace(0, 5, 9)\n",
"print(x)\n"
]
},
@ -623,14 +635,16 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 53,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[2. 3. 4.]\n"
"[3 4 5]\n",
"[1. 1. 1.]\n",
"[3. 4. 5.]\n"
]
}
],
@ -638,8 +652,10 @@
"import numpy as np\n",
"\n",
"a = np.array([3, 4, 5])\n",
"print(a)\n",
"b = np.ones(3)\n",
"print(a - b)\n"
"print(b)\n",
"print(a / b)\n"
]
},
{
@ -651,7 +667,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 39,
"metadata": {},
"outputs": [
{
@ -670,7 +686,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 40,
"metadata": {},
"outputs": [
{
@ -689,17 +705,17 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1, 4],\n",
" [ 9, 16]])"
"array([[ 7, 10],\n",
" [15, 22]])"
]
},
"execution_count": 30,
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
@ -708,6 +724,27 @@
"a * b # mnożenie element po elemencie\n"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 7, 10],\n",
" [15, 22]])"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a @ b # mnożenie macierzowe"
]
},
{
"cell_type": "code",
"execution_count": 31,
@ -907,7 +944,7 @@
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 44,
"metadata": {},
"outputs": [
{
@ -916,7 +953,7 @@
"16"
]
},
"execution_count": 39,
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
@ -1128,7 +1165,7 @@
}
],
"source": [
"x[:, 1]\n"
"x[:, 1] # kolumna nr 1\n"
]
},
{
@ -1148,7 +1185,7 @@
}
],
"source": [
"x[1, :]\n"
"x[1, :] # wiersz nr 1\n"
]
},
{
@ -1352,16 +1389,16 @@
},
{
"cell_type": "code",
"execution_count": 50,
"execution_count": 48,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([2, 0, 7, 3, 5])"
"array([1, 3, 3, 1, 2])"
]
},
"execution_count": 50,
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
@ -1372,16 +1409,16 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": 52,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([-0.7907838 , -0.65971486, 0.0375355 , 2.00045956, 0.32631216])"
"array([ 2.25701199, -0.62666283, -0.58260693, 0.91053811, -0.12398967])"
]
},
"execution_count": 51,
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
@ -1392,16 +1429,16 @@
},
{
"cell_type": "code",
"execution_count": 52,
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1.50130054, 1.20710594, 0.45451505, 0.70098876, 0.90371663])"
"array([0.64188687, 1.98379682, 0.4690363 , 1.26967692, 0.84376779])"
]
},
"execution_count": 52,
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
@ -2220,7 +2257,7 @@
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3.10.6 64-bit",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},