mirror of
https://gitlab.rlp.net/pgp/pgp1-python-einfuehrung
synced 2024-11-16 13:48:11 +00:00
Moved task 4.a. from chapter one to the preparation nb. Added to chapter one a new task just before the fitting chapter. Added a gif which illustrates the wokring principle of curve_fit.
This commit is contained in:
parent
f0a0b71a65
commit
c00a2a743f
4 changed files with 1413 additions and 379 deletions
|
@ -89,8 +89,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:44.802747Z",
|
"end_time": "2019-10-27T12:25:06.022577Z",
|
||||||
"start_time": "2019-09-30T05:49:44.777288Z"
|
"start_time": "2019-10-27T12:25:05.988009Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -281,8 +281,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:44.835098Z",
|
"end_time": "2019-10-27T12:25:06.038328Z",
|
||||||
"start_time": "2019-09-30T05:49:44.820977Z"
|
"start_time": "2019-10-27T12:25:06.026497Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -295,8 +295,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:44.854156Z",
|
"end_time": "2019-10-27T12:25:06.053766Z",
|
||||||
"start_time": "2019-09-30T05:49:44.838216Z"
|
"start_time": "2019-10-27T12:25:06.042411Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -309,8 +309,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:44.869444Z",
|
"end_time": "2019-10-27T12:25:06.069278Z",
|
||||||
"start_time": "2019-09-30T05:49:44.856320Z"
|
"start_time": "2019-10-27T12:25:06.057589Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -330,8 +330,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:44.885272Z",
|
"end_time": "2019-10-27T12:25:06.085191Z",
|
||||||
"start_time": "2019-09-30T05:49:44.871522Z"
|
"start_time": "2019-10-27T12:25:06.071226Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -344,8 +344,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:44.902760Z",
|
"end_time": "2019-10-27T12:25:06.101225Z",
|
||||||
"start_time": "2019-09-30T05:49:44.887994Z"
|
"start_time": "2019-10-27T12:25:06.087057Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -365,8 +365,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:44.919994Z",
|
"end_time": "2019-10-27T12:25:06.116447Z",
|
||||||
"start_time": "2019-09-30T05:49:44.905749Z"
|
"start_time": "2019-10-27T12:25:06.102883Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -379,8 +379,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:44.936549Z",
|
"end_time": "2019-10-27T12:25:06.132372Z",
|
||||||
"start_time": "2019-09-30T05:49:44.922748Z"
|
"start_time": "2019-10-27T12:25:06.119281Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -393,8 +393,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:44.951900Z",
|
"end_time": "2019-10-27T12:25:06.149182Z",
|
||||||
"start_time": "2019-09-30T05:49:44.939383Z"
|
"start_time": "2019-10-27T12:25:06.135155Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -407,8 +407,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:44.968598Z",
|
"end_time": "2019-10-27T12:25:06.164477Z",
|
||||||
"start_time": "2019-09-30T05:49:44.953574Z"
|
"start_time": "2019-10-27T12:25:06.151305Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -428,8 +428,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:44.986417Z",
|
"end_time": "2019-10-27T12:25:06.180459Z",
|
||||||
"start_time": "2019-09-30T05:49:44.970615Z"
|
"start_time": "2019-10-27T12:25:06.167499Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -453,8 +453,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:45.001728Z",
|
"end_time": "2019-10-27T12:25:06.195614Z",
|
||||||
"start_time": "2019-09-30T05:49:44.989743Z"
|
"start_time": "2019-10-27T12:25:06.183176Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -467,8 +467,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:45.017219Z",
|
"end_time": "2019-10-27T12:25:06.211590Z",
|
||||||
"start_time": "2019-09-30T05:49:45.003744Z"
|
"start_time": "2019-10-27T12:25:06.197947Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -481,8 +481,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:45.034800Z",
|
"end_time": "2019-10-27T12:25:06.231469Z",
|
||||||
"start_time": "2019-09-30T05:49:45.019707Z"
|
"start_time": "2019-10-27T12:25:06.212585Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -502,8 +502,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:45.050615Z",
|
"end_time": "2019-10-27T12:25:06.247553Z",
|
||||||
"start_time": "2019-09-30T05:49:45.036793Z"
|
"start_time": "2019-10-27T12:25:06.233424Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -519,8 +519,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:45.067030Z",
|
"end_time": "2019-10-27T12:25:06.279581Z",
|
||||||
"start_time": "2019-09-30T05:49:45.052096Z"
|
"start_time": "2019-10-27T12:25:06.251320Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -602,8 +602,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:45.100616Z",
|
"end_time": "2019-10-27T12:25:06.297413Z",
|
||||||
"start_time": "2019-09-30T05:49:45.084372Z"
|
"start_time": "2019-10-27T12:25:06.284068Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -623,8 +623,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:45.117423Z",
|
"end_time": "2019-10-27T12:25:06.328594Z",
|
||||||
"start_time": "2019-09-30T05:49:45.102607Z"
|
"start_time": "2019-10-27T12:25:06.301834Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -649,8 +649,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:45.133467Z",
|
"end_time": "2019-10-27T12:25:06.344549Z",
|
||||||
"start_time": "2019-09-30T05:49:45.120240Z"
|
"start_time": "2019-10-27T12:25:06.333102Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -675,8 +675,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:45.149030Z",
|
"end_time": "2019-10-27T12:25:06.359679Z",
|
||||||
"start_time": "2019-09-30T05:49:45.135899Z"
|
"start_time": "2019-10-27T12:25:06.347189Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -700,8 +700,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:45.164689Z",
|
"end_time": "2019-10-27T12:25:06.380627Z",
|
||||||
"start_time": "2019-09-30T05:49:45.153880Z"
|
"start_time": "2019-10-27T12:25:06.359679Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -752,8 +752,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:45.198018Z",
|
"end_time": "2019-10-27T12:25:06.397242Z",
|
||||||
"start_time": "2019-09-30T05:49:45.182648Z"
|
"start_time": "2019-10-27T12:25:06.383825Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -774,8 +774,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:45.213392Z",
|
"end_time": "2019-10-27T12:25:06.412442Z",
|
||||||
"start_time": "2019-09-30T05:49:45.200009Z"
|
"start_time": "2019-10-27T12:25:06.402410Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -832,8 +832,8 @@
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2019-09-30T05:49:45.228841Z",
|
"end_time": "2019-10-27T12:25:06.429738Z",
|
||||||
"start_time": "2019-09-30T05:49:45.213392Z"
|
"start_time": "2019-10-27T12:25:06.416013Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
@ -854,6 +854,399 @@
|
||||||
" '''\n",
|
" '''\n",
|
||||||
" return Widerstand * Strom/1000"
|
" return Widerstand * Strom/1000"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Messtabellen in Python:\n",
|
||||||
|
"\n",
|
||||||
|
"Damit euch eine Programmiersprache wie Python Arbeit abnehmen kann, sollte es natürlich auch möglich sein größere Datenmengen z.b. die Werte einer Messtabelle in einer Variablen zu speichern. Python bietet hierfür mehrer verschiedene Konzepte alle mit unterschiedlichen Stärken und Schwächen. Die gängigsten Methoden sind listen, tuple, bzw. so genannte numpy.arrays und pandas.dataframes. Aufgrund der imitierten Zeit im PGP 1 werden wir uns hier lediglich mit zwei dieser vier Methoden auseinander setzen. \n",
|
||||||
|
"\n",
|
||||||
|
"Fangen wir zunächst mit Listen an. Eine Liste ist eine Ansammlung von Werten, welche alle den gleichen oder ganz unterschiedliche Datentypen haben können. Eine Liste kann auf zwei unterschiedliche Art und Weisen erstellt werden:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:25:06.446484Z",
|
||||||
|
"start_time": "2019-10-27T12:25:06.432594Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"Messwerte1 = ['Wert1', 'Wert2', 'Wert3'] # Variante 1\n",
|
||||||
|
"Messwerte1"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:25:06.477151Z",
|
||||||
|
"start_time": "2019-10-27T12:25:06.449263Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"Messwerte2 = list([2, 0.9, '1']) # Variante 2\n",
|
||||||
|
"Messwerte2"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Sobald wir eine liste erstellt haben können wir eine ganze Reihe von unterschiedlichen Manipulationen durchführen um sie nach unserem belieben zu verändern.\n",
|
||||||
|
"\n",
|
||||||
|
"Wir können zum Beispiel die bestehende Liste um ein Wert erweitern (`append`) oder einen zusätzlichen Wert an eine beliebige Stelle in der Liste hinzufügen (`insert`)."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:25:06.492972Z",
|
||||||
|
"start_time": "2019-10-27T12:25:06.480376Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"Messwerte1.append('Wert5')\n",
|
||||||
|
"Messwerte1"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:25:06.509050Z",
|
||||||
|
"start_time": "2019-10-27T12:25:06.496701Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"Messwerte1.insert(4, 'Wert4')\n",
|
||||||
|
"Messwerte1"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Ups, was ist denn in der letzten Zelle passiert? Wert4 wurde ja garnicht an Stelle 4 der Liste gesetzt, Python scheint nicht zählen zu können... \n",
|
||||||
|
"\n",
|
||||||
|
"Leider zählt Python doch richtig. In Python läuft der index von objekten in einer Liste oder ähnlichem immer von 0,1,2,3...n. Dies können wir auch ganz einfach überprüfen in dem wir unsere Liste in verschiedene \"Scheiben\" schneiden (so genanntes slicing). Dies geht wie folgt:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:25:06.524167Z",
|
||||||
|
"start_time": "2019-10-27T12:25:06.511411Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"NeueWerte = ['Wert1', 'Wert2', 'Wert3', 'Wert4', 'Wert5', 'Wert6'] "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Die kleinste Scheibe welche wir abschneiden können ist ein einzelner Wert:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:25:06.540756Z",
|
||||||
|
"start_time": "2019-10-27T12:25:06.525161Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"NeueWerte[0] # Hier seht ihr, dass der erste Wert den Index 0 hat."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:25:06.556003Z",
|
||||||
|
"start_time": "2019-10-27T12:25:06.541754Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"wert_index_2 = NeueWerte[2] \n",
|
||||||
|
"wert_index_2"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Wie bei einer Pizza können wir uns natürlich auch größere Stücke nehmen."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:25:06.571456Z",
|
||||||
|
"start_time": "2019-10-27T12:25:06.561307Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"NeueWerte[0:3] "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:25:06.603263Z",
|
||||||
|
"start_time": "2019-10-27T12:25:06.579819Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"NeueWerte[2:5] # Ihr seht Python behandelt den letzten Wert wie in einem offenen Intervall [2,5)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:25:06.634032Z",
|
||||||
|
"start_time": "2019-10-27T12:25:06.607460Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"NeueWerte[2:] # Hier werden alle Werte mit dem Index >= 2 zurück gegeben"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:25:06.649485Z",
|
||||||
|
"start_time": "2019-10-27T12:25:06.635504Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"NeueWerte[-3:] # Mit negativen Zahlen fangt ihr vom Ende der Liste an"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Neben `insert`, `append` und `slicing` bietet Python noch ein paar weitere Listenmanipulationen an. Mit Hilfe des `+` Operators könnt ihr die Werte in einer Liste direkt an eine andere Liste anfügen."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:25:06.680320Z",
|
||||||
|
"start_time": "2019-10-27T12:25:06.654941Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"Messwerte1 + NeueWerte"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:22:59.315752Z",
|
||||||
|
"start_time": "2019-10-27T12:22:59.289651Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"Anders als `append` welches die zweite Liste als ganzes an die erste Liste anfügt:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:25:06.696566Z",
|
||||||
|
"start_time": "2019-10-27T12:25:06.684462Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"Messwerte1.append(NeueWerte)\n",
|
||||||
|
"Messwerte1"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Aber aufgepasst bei `append` wird eure Liste an welche ihr die Daten anhängt (hier Messwerte1) direkt geändert (dies gilt auch für `insert`), während ihr beim `+` Operator die Variable überschreiben müsst damit die Änderung wirksam wird. "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:25:06.712798Z",
|
||||||
|
"start_time": "2019-10-27T12:25:06.700559Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"Messwerte1 = Messwerte1 + NeueWerte\n",
|
||||||
|
"# Tipp dies könnt ihr auch einfach mit Hilfe von\n",
|
||||||
|
"# Messwerte1 += NeueWerte\n",
|
||||||
|
"Messwerte1"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Zwei weitere nützliche Befehle im zusammenhang von listen ist die `len`- und `range`-Funktion. \n",
|
||||||
|
"\n",
|
||||||
|
"`len` gibt euch die Länge einer Liste zurück "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:25:06.728109Z",
|
||||||
|
"start_time": "2019-10-27T12:25:06.716256Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"print(Messwerte1)\n",
|
||||||
|
"len(Messwerte1)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"`range` erstellt euch ganzzahlige Werte zwischen zwei ganzen Zahlen "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:25:06.745008Z",
|
||||||
|
"start_time": "2019-10-27T12:25:06.731772Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"range(0, # <-- Startwert\n",
|
||||||
|
" 5, # <-- Endwert (nicht mehr enthalten, offenes Ende)\n",
|
||||||
|
" 2 # <-- Schrittweite\n",
|
||||||
|
" )"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Ihr könnt die `range` Rückgabe auch wieder in eine Liste umwandeln mit"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:25:06.760820Z",
|
||||||
|
"start_time": "2019-10-27T12:25:06.748599Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"list(range(0,5,2))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2019-10-27T12:24:39.369806Z",
|
||||||
|
"start_time": "2019-10-27T12:24:39.330456Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"<div class=task>\n",
|
||||||
|
" \n",
|
||||||
|
"#### Aufgabe 4.a.: Erstellen von Messwerttabellen:\n",
|
||||||
|
"\n",
|
||||||
|
"Erstelle für jede Spalte (außer der Messwertnummer) der nachfolgende Messtabelle eine Liste welche die Messdaten beinhaltet. Benutze anschließend den `append` Befehl um deine Spaltendaten an eine weitere Liste namens *daten* anzuhängen. \n",
|
||||||
|
"\n",
|
||||||
|
"| Messwertnummer | Spannung [V] | Strom [mA] | Fehler der Spannung [V] | Fehler des Stroms in [mA] |\n",
|
||||||
|
"|----------------|--------------|------------|-------------------------|---------------------------|\n",
|
||||||
|
"| 1 | 12.00 | 110 | 0.32 | 10 |\n",
|
||||||
|
"| 2 | 11.78 | 98 | 0.15 | 10 |\n",
|
||||||
|
"| 3 | 12.56 | 102 | 0.63 | 10 |\n",
|
||||||
|
"| 4 | 12.34 | 124 | 0.12 | 10 |\n",
|
||||||
|
"| 5 | 12.01 | 105 | 0.20 | 10 |\n",
|
||||||
|
"| 6 | 11.94 | 95 | 0.17 | 10 |\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"Verwende anschließend das Slicing um die umgesetzte Leistung im Widerstand für die Meswerte 3 und 5 zu berechnen.\n",
|
||||||
|
"\n",
|
||||||
|
"**Tipp:**\n",
|
||||||
|
"\n",
|
||||||
|
"1. Ihr habt bereits die Funktionen für die Leistung in Aufgabe 3 definiert und könnt sie hier erneut verwenden. \n",
|
||||||
|
"2. Das Sclicen von verschachtelten Listen funktioniert genauso wie bei normalen Listen: \n",
|
||||||
|
"\n",
|
||||||
|
"```python\n",
|
||||||
|
"spalte0 = daten[0] #<-- Wählt die Spalte 0 an \n",
|
||||||
|
"spalte0[2] #<-- Wählt aus Spalte 0 den Messwert mit Index 2 an\n",
|
||||||
|
"# oder als Einzeiler:\n",
|
||||||
|
"daten[0][2] \n",
|
||||||
|
"```\n",
|
||||||
|
"\n",
|
||||||
|
"3. Wie verhält sich die Messwertnummer zum Listenindex?\n",
|
||||||
|
"<div>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
|
|
File diff suppressed because one or more lines are too long
BIN
images/MaterialPythonkurs092018/Fitting_gif.gif
Normal file
BIN
images/MaterialPythonkurs092018/Fitting_gif.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 193 KiB |
BIN
images/MaterialPythonkurs092018/Gaußverteilung.png
Normal file
BIN
images/MaterialPythonkurs092018/Gaußverteilung.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
Loading…
Reference in a new issue