Wichtige Libraries
Numpy
Array
import numpy as np
x = np.arange(10)
x + 1
(x + 1)**2
np.sin(x)
x > 3
2-D Arrays
table = np.arange(50).reshape(10,5)
table**2
Matrix
a = np.mat([[4, 3], [2, 1]])
b = np.mat([[1, 2], [3, 4]])
a * b
Matplotlib
Plot
import matplotlib.pyplot as plt
import numpy as np
t = np.linspace(0, 2*np.pi, 500)
plt.plot(t, np.sin(t))
plt.show()
Sankey
import matplotlib.pyplot as plt
from matplotlib.sankey import Sankey
s = Sankey()
s.add(flows=[0.7, 0.3, -0.5, -0.5],
labels=['a', 'b', 'c', 'd'],
orientations=[1, 1, -1, 0])
s.finish()
plt.show()
Pandas
import pandas as pd
df = pd.read_csv('SchPark01.csv',
sep=';',
header = None,
names = ['date', 'time', 'Gh', 'Ta'],
parse_dates = [[0, 1]],
skipinitialspace=True,
index_col = 0
)
df.Gh['2011-07-07 12:30']
df.Ta.mean()
df.plot()
Sympy
import sympy
from sympy.solvers import solve
x = sympy.Symbol('x')
solve(sympy.Eq(x**2, x + 1), x)
sympy.expand(x * (x + 1) * (x + 3))
Optimize
from scipy.optimize import minimize
def f(x):
return (x[0] + 2)**2 + (x[1] - 3)**2
minimize(f, [0, 0])
Uncertainties
# pip install uncertainties
from uncertainties import ufloat, umath
x = ufloat(39.5, 0.5)
x**2
umath.log(x)
y = x + 2
y
y - x
Many others