Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1dce636192 | ||
![]() |
2a998611bf | ||
0882dd06f3 |
@@ -25,5 +25,8 @@ CC-BY-SA Olli Graf
|
|||||||
|18 | Generatoren und list comprehension|
|
|18 | Generatoren und list comprehension|
|
||||||
|19 | Webseiten (Flask)|
|
|19 | Webseiten (Flask)|
|
||||||
|20 | virtuelle Umgebungen|
|
|20 | virtuelle Umgebungen|
|
||||||
|21 | Interrupts & Signale|
|
|22 | Numpy|
|
||||||
|
|21 | Matplotlib|
|
||||||
|
|23 | Pandas|
|
||||||
|
|
||||||
|
|
||||||
|
4
teil22/.gitignore
vendored
Normal file
4
teil22/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# created by virtualenv automatically
|
||||||
|
__pycache__
|
||||||
|
bin
|
||||||
|
lib
|
18
teil22/StressFile.py
Normal file
18
teil22/StressFile.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import io
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
class StressFile:
|
||||||
|
def readOutFile(self,filename):
|
||||||
|
result = {
|
||||||
|
'frequency': [],
|
||||||
|
'temperatures': []
|
||||||
|
}
|
||||||
|
with open(filename,'r') as f:
|
||||||
|
content = f.readlines()
|
||||||
|
print(f'conent= {content}')
|
||||||
|
|
||||||
|
|
||||||
|
sf = StressFile()
|
||||||
|
|
||||||
|
sf.readOutFile('./kodos.out')
|
||||||
|
|
42
teil22/calc_array.py
Normal file
42
teil22/calc_array.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
# Array initialisieren
|
||||||
|
org = np.array([1,2,3,4,5,6])
|
||||||
|
|
||||||
|
|
||||||
|
# Kopiert das int64 Array in ein float64 Array
|
||||||
|
def copy_to_float64(source):
|
||||||
|
liste = []
|
||||||
|
|
||||||
|
for i in range(source.shape[1]):
|
||||||
|
liste.append(float(source[i]))
|
||||||
|
|
||||||
|
return np.array(liste,dtype=float64)
|
||||||
|
|
||||||
|
|
||||||
|
# Ein paar Kopien anlegen
|
||||||
|
copy_sum = org.copy()
|
||||||
|
copy_mult = org.copy()
|
||||||
|
copy_diff = org.copy()
|
||||||
|
copy_div = org.astype(np.float64).copy()
|
||||||
|
|
||||||
|
# Zu allen Elementen 2 dazuzählen
|
||||||
|
copy_sum += 2
|
||||||
|
|
||||||
|
print(f'copy_sum={copy_sum}')
|
||||||
|
|
||||||
|
# Alle Elemente mit 2 multiplizieren
|
||||||
|
copy_mult *= 2
|
||||||
|
|
||||||
|
print(f'copy_mult={copy_mult}')
|
||||||
|
|
||||||
|
|
||||||
|
# Von allen Elementen 1 abziehen
|
||||||
|
copy_diff -= 1
|
||||||
|
|
||||||
|
print(f'copy_diff={copy_diff}')
|
||||||
|
|
||||||
|
copy_div /=2
|
||||||
|
|
||||||
|
print(f'copy_div={copy_div}')
|
||||||
|
|
20
teil22/copyarray.py
Normal file
20
teil22/copyarray.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
org = np.array([1,2,3,4,5,6])
|
||||||
|
|
||||||
|
copy = org
|
||||||
|
|
||||||
|
print(f'org= {org}')
|
||||||
|
print(f'copy={copy}')
|
||||||
|
|
||||||
|
copy[2]= 7
|
||||||
|
|
||||||
|
print(f'org= {org}')
|
||||||
|
print(f'copy={copy}')
|
||||||
|
|
||||||
|
copy2 = org.copy()
|
||||||
|
|
||||||
|
copy2[2]= 3
|
||||||
|
|
||||||
|
print(f'org= {org}')
|
||||||
|
print(f'copy2={copy2}')
|
9
teil22/reshape.py
Normal file
9
teil22/reshape.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
a = np.array([1,2,3,4,5,6,7,8,9,10])
|
||||||
|
|
||||||
|
print(f'orignal {a}')
|
||||||
|
|
||||||
|
reshaped = a.reshape(2,5)
|
||||||
|
|
||||||
|
print(f'reshaped {reshaped}')
|
7
teil22/rndm.py
Normal file
7
teil22/rndm.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
#Erzeuge 1 Mio Zufallszahlen
|
||||||
|
random_np = np.random(100000)
|
||||||
|
|
||||||
|
random_list = list(random_np)
|
||||||
|
|
6
teil22/shape.py
Normal file
6
teil22/shape.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
twodim_array = np.array([[1,2,3,4,5],[1,4,9,16,25]])
|
||||||
|
|
||||||
|
print(f'shape is {twodim_array.shape}')
|
||||||
|
|
9
teil22/simplearray.py
Normal file
9
teil22/simplearray.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
simple_array = np.array([1,2,3,4,5,6])
|
||||||
|
|
||||||
|
print(f'simple_array={simple_array}')
|
||||||
|
print(f'ndim={simple_array.ndim}')
|
||||||
|
print(f'dtype={simple_array.dtype}')
|
||||||
|
print(f'shape is {simple_array.shape}')
|
9
teil22/twodimarray.py
Normal file
9
teil22/twodimarray.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
twodim_array = np.array([[1,2,3,4,5],[1,4,9,16,25]],dtype='int32')
|
||||||
|
|
||||||
|
print(f'twodim_array={twodim_array}')
|
||||||
|
print(f'ndim={twodim_array.ndim}')
|
||||||
|
print(f'dtype={twodim_array.dtype}')
|
||||||
|
print(f'shape is {twodim_array.shape}')
|
||||||
|
|
6
teil23/.gitignore
vendored
Normal file
6
teil23/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# created by virtualenv automatically
|
||||||
|
__pycache__
|
||||||
|
bin
|
||||||
|
lib
|
||||||
|
share
|
||||||
|
*.csv
|
20
teil23/iospeed_balken.py
Executable file
20
teil23/iospeed_balken.py
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
#! ./bin/python
|
||||||
|
#encoding: utf-8
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
labels = [ 'Pineberry Pi pcie1_gen=2','Pineberry Pi pcie1_gen=3', 'MicroSD Raspi 5', 'MicroSD Raspi 4']
|
||||||
|
io_read= np.array([148.50,171.99,30.85,10.15])
|
||||||
|
io_write = np.array([99.15,114.97,20.45,6.63])
|
||||||
|
legend = ['Schreiben','Lesen']
|
||||||
|
#Höhe der Balken
|
||||||
|
__hoehe__ =0.6
|
||||||
|
|
||||||
|
fig,ax = plt.subplots()
|
||||||
|
|
||||||
|
|
||||||
|
plt.barh(labels,io_write,__hoehe__)
|
||||||
|
plt.barh(labels,io_read,__hoehe__,left=io_write)
|
||||||
|
plt.legend(legend)
|
||||||
|
plt.show()
|
||||||
|
|
30
teil23/normparabel_graph.py
Executable file
30
teil23/normparabel_graph.py
Executable file
@@ -0,0 +1,30 @@
|
|||||||
|
#! ./bin/python
|
||||||
|
# encoding:utf-8
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
def plot_normal_parabel():
|
||||||
|
# Erzeuge Datenpunkte für x-Werte von -10 bis 10
|
||||||
|
x = np.linspace(-3, 3, 100)
|
||||||
|
|
||||||
|
# Berechne die y-Werte für die Normalparabel
|
||||||
|
y = x**2
|
||||||
|
|
||||||
|
# Erstelle das Diagramm
|
||||||
|
plt.plot(x, y, label='Normalparabel: $y=x^2$')
|
||||||
|
|
||||||
|
# Beschriftungen und Titel hinzufügen
|
||||||
|
plt.xlabel('x-Achse')
|
||||||
|
plt.ylabel('y-Achse')
|
||||||
|
plt.title('Normalparabel')
|
||||||
|
|
||||||
|
# Legende hinzufügen
|
||||||
|
plt.legend()
|
||||||
|
|
||||||
|
|
||||||
|
# Funktion aufrufen, um die Normalparabel zu zeichnen
|
||||||
|
plot_normal_parabel()
|
||||||
|
|
||||||
|
# Diagramm anzeigen
|
||||||
|
plt.grid(True)
|
||||||
|
plt.show()
|
8
teil23/pyvenv.cfg
Normal file
8
teil23/pyvenv.cfg
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
home = /usr/bin
|
||||||
|
implementation = CPython
|
||||||
|
version_info = 3.11.2.final.0
|
||||||
|
virtualenv = 20.17.1+ds
|
||||||
|
include-system-site-packages = false
|
||||||
|
base-prefix = /usr
|
||||||
|
base-exec-prefix = /usr
|
||||||
|
base-executable = /usr/bin/python3
|
45
teil23/sinus_parabel_graph.py
Executable file
45
teil23/sinus_parabel_graph.py
Executable file
@@ -0,0 +1,45 @@
|
|||||||
|
#! ./bin/python
|
||||||
|
# encoding:utf-8
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
def plot_normal_parabel():
|
||||||
|
# Erzeuge Datenpunkte für x-Werte von -10 bis 10
|
||||||
|
x = np.linspace(-3, 3, 100)
|
||||||
|
|
||||||
|
# Berechne die y-Werte für die Normalparabel
|
||||||
|
y = x**2
|
||||||
|
|
||||||
|
# Erstelle das Diagramm
|
||||||
|
plt.plot(x, y, label='Normalparabel: $y=x^2$')
|
||||||
|
|
||||||
|
# Beschriftungen und Titel hinzufügen
|
||||||
|
plt.xlabel('x-Achse')
|
||||||
|
plt.ylabel('y-Achse')
|
||||||
|
plt.title('Normalparabel')
|
||||||
|
|
||||||
|
# Legende hinzufügen
|
||||||
|
plt.legend()
|
||||||
|
|
||||||
|
|
||||||
|
def plot_sinus_function():
|
||||||
|
# Erzeuge Datenpunkte für x-Werte von -2π bis 2π
|
||||||
|
x = np.linspace(-2 * np.pi, 2 * np.pi, 100)
|
||||||
|
|
||||||
|
# Berechne die y-Werte für die Sinusfunktion
|
||||||
|
y = np.sin(x)
|
||||||
|
|
||||||
|
# Erstelle das Diagramm für die Sinusfunktion
|
||||||
|
plt.plot(x, y, label='Sinusfunktion: $y = \sin(x)$', color='blue')
|
||||||
|
|
||||||
|
# Legende hinzufügen
|
||||||
|
plt.legend()
|
||||||
|
|
||||||
|
|
||||||
|
# Funktion aufrufen, um die Normalparabel zu zeichnen
|
||||||
|
plot_normal_parabel()
|
||||||
|
plot_sinus_function()
|
||||||
|
|
||||||
|
# Diagramm anzeigen
|
||||||
|
plt.grid(True)
|
||||||
|
plt.show()
|
24
teil23/test.py
Normal file
24
teil23/test.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
# Koordinaten
|
||||||
|
x = np.arange(5, 10)
|
||||||
|
y = np.arange(12, 17)
|
||||||
|
|
||||||
|
print(f'x={x}')
|
||||||
|
print(f'y={y}')
|
||||||
|
|
||||||
|
# Plot
|
||||||
|
plt.plot(x,y)
|
||||||
|
|
||||||
|
# Titel hinzufügen
|
||||||
|
plt.title("Matplotlib PLot NumPy Array")
|
||||||
|
|
||||||
|
# Beschriftung für die Achsen
|
||||||
|
|
||||||
|
plt.xlabel("x Achse")
|
||||||
|
plt.ylabel("y Achse")
|
||||||
|
|
||||||
|
# Fenster anzeigen
|
||||||
|
plt.show()
|
23
teil23/verkauf_stapel.py
Executable file
23
teil23/verkauf_stapel.py
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
#! ./bin/python
|
||||||
|
#encoding: utf-8
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
jahre= np.array(['2018','2019', '2020'])
|
||||||
|
aepfel= np.array([1000,1500,2000])
|
||||||
|
erdbeeren =np.array([500,950,900])
|
||||||
|
bananen=np.array([400,800,750])
|
||||||
|
breite = 0.6
|
||||||
|
|
||||||
|
fig,ax = plt.subplots()
|
||||||
|
|
||||||
|
|
||||||
|
#ax.legend('Verkäufe')
|
||||||
|
ax.bar(jahre,bananen,color='yellow')
|
||||||
|
ax.bar(jahre,erdbeeren,bottom=bananen,color='red')
|
||||||
|
ax.bar(jahre,aepfel,bottom=erdbeeren,color='green')
|
||||||
|
|
||||||
|
plt.legend(['Bananen','Erdbeeren','Äpfel'])
|
||||||
|
|
||||||
|
plt.show()
|
47
teil23/vornamen_reader.py
Normal file
47
teil23/vornamen_reader.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#encoding: utf-8
|
||||||
|
|
||||||
|
def read_vornamen(filename):
|
||||||
|
dict = {}
|
||||||
|
# Der Zähler dient nur dazu, die erste Zeile zu überspringen
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
dict['mädchen'] = 0
|
||||||
|
dict['jungs'] = 0
|
||||||
|
dict['divers'] = 0
|
||||||
|
with open(filename,'r') as f:
|
||||||
|
for zeile in f:
|
||||||
|
if count >0:
|
||||||
|
# einzelne Zeile in seine Bestandteile zerlegen
|
||||||
|
splitted = zeile.strip().split(';')
|
||||||
|
anzahl = splitted[0]
|
||||||
|
vorname = splitted[1]
|
||||||
|
geschlecht= splitted[2]
|
||||||
|
position = splitted[3]
|
||||||
|
|
||||||
|
if geschlecht == 'w':
|
||||||
|
dict['mädchen'] += 1
|
||||||
|
elif geschlecht == 'm':
|
||||||
|
dict['jungs'] += 1
|
||||||
|
else:
|
||||||
|
dict['divers'] += 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
data = {}
|
||||||
|
data['vorname'] = vorname
|
||||||
|
data['anzahl'] = int(anzahl)
|
||||||
|
data['geschlecht'] = geschlecht
|
||||||
|
data['position'] = position
|
||||||
|
if vorname not in dict:
|
||||||
|
dict[vorname] = data
|
||||||
|
else:
|
||||||
|
# doppelte Einträge summieren wir auf.
|
||||||
|
e = dict[vorname]
|
||||||
|
e['anzahl'] = int(anzahl) + (e['anzahl'])
|
||||||
|
count +=1
|
||||||
|
|
||||||
|
gesamt = dict['jungs'] + dict['mädchen'] + dict['divers']
|
||||||
|
|
||||||
|
dict['gesamt'] = gesamt
|
||||||
|
return dict
|
||||||
|
|
42
teil23/vornamen_sauelen.py
Executable file
42
teil23/vornamen_sauelen.py
Executable file
@@ -0,0 +1,42 @@
|
|||||||
|
#! ./bin/python
|
||||||
|
#encondig: utf-8
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from vornamen_reader import read_vornamen
|
||||||
|
|
||||||
|
|
||||||
|
def plot_geschlecht(vornamen):
|
||||||
|
|
||||||
|
bez= ['Mädchen', 'Jungs','divers']
|
||||||
|
geburten = [vornamen['mädchen'], vornamen['jungs'],vornamen['divers']]
|
||||||
|
|
||||||
|
print(f'geburten={geburten}')
|
||||||
|
|
||||||
|
farben = ['red','blue','green']
|
||||||
|
|
||||||
|
fig, ax = plt.subplots()
|
||||||
|
print(f'fig={fig}')
|
||||||
|
print(f'ax={ax}')
|
||||||
|
|
||||||
|
ax.bar(bez,geburten,label=bez, color=farben)
|
||||||
|
ax.set_ylabel('Geburten')
|
||||||
|
ax.set_title('Geburten nach Geschlecht Wuppertal 2020')
|
||||||
|
ax.legend(title='Geburten')
|
||||||
|
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
vornamen = read_vornamen('./Vornamen_Wuppertal_2020.csv')
|
||||||
|
|
||||||
|
jungs= vornamen['jungs']
|
||||||
|
maedels = vornamen['mädchen']
|
||||||
|
divers = vornamen['divers']
|
||||||
|
|
||||||
|
print(f'Jungs: {jungs}')
|
||||||
|
print(f'Mädchen: {maedels}')
|
||||||
|
print(f'divers: {divers}')
|
||||||
|
# print(f'vornamen={vornamen}')
|
||||||
|
|
||||||
|
plot_geschlecht(vornamen)
|
||||||
|
|
||||||
|
|
43
teil23/vornamen_torte.py
Executable file
43
teil23/vornamen_torte.py
Executable file
@@ -0,0 +1,43 @@
|
|||||||
|
#! ./bin/python
|
||||||
|
#encondig: utf-8
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import logging
|
||||||
|
from vornamen_reader import read_vornamen
|
||||||
|
|
||||||
|
logging.basicConfig( format='%(asctime)-15s [%(levelname)s] %(funcName)s: %(message)s', level=logging.INFO)
|
||||||
|
|
||||||
|
def plot_geschlecht(vornamen):
|
||||||
|
|
||||||
|
bez= ['Mädchen', 'Jungs','divers']
|
||||||
|
geburten = [vornamen['mädchen'], vornamen['jungs'],vornamen['divers']]
|
||||||
|
|
||||||
|
logging.info(f'geburten={geburten}')
|
||||||
|
|
||||||
|
proz_maedels = round(vornamen['mädchen'] / vornamen['gesamt'] *100,2)
|
||||||
|
proz_jungs = round(vornamen['jungs'] / vornamen['gesamt'] *100,2)
|
||||||
|
proz_divers = round(vornamen['divers'] / vornamen['gesamt'] *100,2)
|
||||||
|
|
||||||
|
farben = ['red','blue','green']
|
||||||
|
sizes= [proz_maedels,proz_jungs,proz_divers]
|
||||||
|
|
||||||
|
logging.info(f'sizes={sizes}')
|
||||||
|
|
||||||
|
fig, ax = plt.subplots()
|
||||||
|
|
||||||
|
ax.pie(sizes,explode=(0,0,0), labels=bez,autopct='%1.1f%%',shadow=True,startangle=90)
|
||||||
|
ax.axis('equal')
|
||||||
|
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
vornamen = read_vornamen('./Vornamen_Wuppertal_2020.csv')
|
||||||
|
|
||||||
|
jungs= vornamen['jungs']
|
||||||
|
maedels = vornamen['mädchen']
|
||||||
|
divers = vornamen['divers']
|
||||||
|
|
||||||
|
|
||||||
|
plot_geschlecht(vornamen)
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user