Skip to content

Instantly share code, notes, and snippets.

View nschloe's full-sized avatar
👨‍💻
doing math

Nico Schlömer nschloe

👨‍💻
doing math
View GitHub Profile
@nschloe
nschloe / plot-optimization-tests.py
Last active February 3, 2022 16:51
Plot optimization test functions
import matplotx
import matplotlib.pyplot as plt
import numpy as np
class Rastrigin:
def __init__(self):
self.roots = np.array([[0, 0]])
def f(self, x):
@nschloe
nschloe / cplot-lambert-series.py
Last active February 12, 2022 21:38
cplot Lambert series
import cplot
import numpy as np
def lambert_series(z, n=100):
zn = z.copy()
s = np.zeros_like(z)
for _ in range(n):
s += zn / (1 - zn)
zn *= z
@nschloe
nschloe / fj-cplot-demo.py
Created February 16, 2022 21:48
cplot demo
# https://gist.github.com/fredrik-johansson/4098b7aea7e0321ac50bb533a03515d0
import cplot
import matplotlib.pyplot as plt
import mpmath
import numpy as np
from mpmath import fp
def _wrap(fun):
@nschloe
nschloe / integer-write-comparison.py
Created March 30, 2022 18:11
Python/NumPy integer ASCII writes
import perfplot
import numpy as np
def setup(n):
return np.random.randint(0, 100, (n, 4))
def loop(data):
with open("f.txt", "w") as f:
@nschloe
nschloe / means.py
Last active November 24, 2022 17:56
plot generalized means
import numpy as np
import matplotlib.pyplot as plt
def agm(an, bn):
while np.any(abs(an - bn) > 1.0e-15):
an, bn = (an + bn) / 2, np.sqrt(an * bn)
return an
x = np.linspace(0, 4, 401)
@nschloe
nschloe / read-comparison.py
Last active January 28, 2023 20:08
Python array I/O comparison
from sys import version_info
import matplotlib.pyplot as plt
import perfplot
import pickle
import netCDF4
import numpy as np
import h5py
import tables
@nschloe
nschloe / write-comparison.py
Created January 27, 2023 21:42
Python array I/O comparison
from sys import version_info
import matplotlib.pyplot as plt
import perfplot
import pickle
import netCDF4
import numpy as np
import h5py
import tables
@nschloe
nschloe / sphere-vol.py
Created May 9, 2023 18:55
Volumes of spheres of radius 1 in higher dimensions
from math import tau
import matplotlib.pyplot as plt
n_max = 20
sphere_vols = [2, tau]
for n in range(3, n_max + 1):
sphere_vols.append(sphere_vols[n-2] * tau / (n-2))
plt.plot(range(1, n_max + 1), sphere_vols, "o")