Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.
Quelldateien prüfen
Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Ein direkter Befehl überspringt den Prüf-Prompt. Prüfen Sie die Quelle, bevor Sie ihn ausführen.
from scipy import odr
import numpy as np
# Pattern: Model → Data → Fit → Analyze# 1. Define modeldefmodel_func(B, x):
return B[0] * x + B[1]
# 2. Prepare data with errors
x = np.array([1, 2, 3, 4, 5])
y = np.array([2.1, 3.9, 6.2, 7.8, 10.1])
sx = np.array([0.1, 0.1, 0.1, 0.1, 0.1])
sy = np.array([0.2, 0.2, 0.2, 0.2, 0.2])
data = odr.RealData(x, y, sx=sx, sy=sy)
model = odr.Model(model_func)
# 3. Fit
odr_obj = odr.ODR(data, model, beta0=[1., 0.])
output = odr_obj.run()
# 4. Analyze results
output.pprint()
print(f"Chi-square: {output.res_var}")
Iterative Solver Pattern
from scipy.sparse import linalg as splinalg
from scipy import sparse
import numpy as np
# Pattern: Precondition → Solve → Check Convergence
A = sparse.csr_array([[3, 0, 1], [0, 4, 0], [1, 0, 2]])
b = np.array([1, 2, 3])
# 1. Create preconditioner
M = sparse.diags(1.0 / A.diagonal())
# 2. Solve with callbackdefcallback(xk):
print(f"Residual: {np.linalg.norm(A @ xk - b)}")
x, info = splinalg.cg(A, b, M=M, callback=callback, tol=1e-5)
# 3. Check convergenceif info == 0:
print("Converged successfully")
elif info > 0:
print(f"Converged after {info} iterations")
else:
print("Failed to converge")
Signal Processing Pipeline
from scipy import signal
import numpy as np
# Pattern: Design → Filter → Analyze# 1. Design filter
fs = 1000# Sample rate
b, a = signal.butter(4, [10, 100], btype='band', fs=fs)
# 2. Apply filter
data = np.random.randn(10000)
filtered = signal.filtfilt(b, a, data)
# 3. Analyze
f, Pxx = signal.welch(filtered, fs=fs)
peaks, _ = signal.find_peaks(Pxx, height=0.1)
Sparse Matrices
Creating Sparse Arrays
import numpy as np
from scipy import sparse
# COO (Coordinate) format - good for construction
row = np.array([0, 1, 2, 0])
col = np.array([0, 1, 2, 2])
data = np.array([1, 2, 3, 4])
coo = sparse.coo_array((data, (row, col)), shape=(3, 3))
# CSR (Compressed Sparse Row) - efficient row operations
csr = sparse.csr_array([[1, 0, 2], [0, 3, 0]])
# CSC (Compressed Sparse Column) - efficient column operations
csc = sparse.csc_array([[1, 0, 2], [0, 3, 0]])
# DOK (Dictionary of Keys) - incremental construction
dok = sparse.dok_array((5, 5))
dok[0, 0] = 1
dok[1, 2] = 2# LIL (List of Lists) - incremental construction
lil = sparse.lil_array((10, 10))
lil[0, :5] = 1
lil[1, 5:] = 2# From dense array
dense = np.eye(100)
sparse_eye = sparse.csr_array(dense)
Format Conversion
# Convert between formats
coo = sparse.coo_array([[1, 0], [0, 2]])
csr = coo.tocsr()
csc = coo.tocsc()
dense = coo.toarray()
# Each format has different strengths:# - COO: construction, converting to other formats# - CSR: row slicing, matrix-vector products# - CSC: column slicing, matrix-vector products# - DOK: element access and incremental construction# - LIL: incremental construction, changing sparsity structure
Sparse Array Operations
from scipy import sparse
import numpy as np
# Create sparse matrices
a = sparse.csr_array([[1, 0, 2], [0, 3, 0]])
b = sparse.csr_array([[0, 1], [2, 0], [0, 3]])
# Matrix multiplication
c = a @ b # or a.dot(b)# Element-wise operations
doubled = a * 2
added = a + a
# Reduction operations
total = a.sum()
row_max = a.max(axis=1)
col_mean = a.mean(axis=0)
# Indexing (CSR/CSC formats)
element = a[0, 2]
row = a[1, :]
submatrix = a[:2, :2]
# Eliminate explicit zeros
a.eliminate_zeros()
# Sum duplicate entries
a.sum_duplicates()
Sparse Linear Algebra
from scipy.sparse import linalg as splinalg
from scipy import sparse
import numpy as np
# Create a sparse system
A = sparse.csr_array([[3, 0, 1], [0, 4, 0], [1, 0, 2]])
b = np.array([1, 2, 3])
# Solve linear system Ax = b
x = splinalg.spsolve(A, b)
# Iterative solvers for large systems
x, info = splinalg.cg(A, b) # Conjugate gradient
x, info = splinalg.gmres(A, b) # GMRES# Eigenvalue problems
eigenvalues, eigenvectors = splinalg.eigs(A, k=2)
# Matrix norms
norm = splinalg.norm(A)
from scipy import spatial
import numpy as np
# Distance calculations
points1 = np.array([[0, 0], [1, 1]])
points2 = np.array([[2, 2], [3, 3]])
# Euclidean distance
dist = spatial.distance.euclidean(points1[0], points2[0])
# Distance matrix
dist_matrix = spatial.distance.cdist(points1, points2)
# K-D Tree for nearest neighbor search
points = np.random.rand(1000, 2)
tree = spatial.KDTree(points)
# Query nearest neighbors
distances, indices = tree.query([0.5, 0.5], k=5)
# Convex hull
hull = spatial.ConvexHull(points)
# Delaunay triangulation
tri = spatial.Delaunay(points)
# Voronoi diagram
vor = spatial.Voronoi(points)
Constants
from scipy import constants
# Physical constants
c = constants.c # Speed of light
h = constants.h # Planck constant
e = constants.e # Elementary charge
G = constants.G # Gravitational constant# Mathematical constants
pi = constants.pi
golden = constants.golden
# Unit conversions
mile_in_meters = constants.mile
hour_in_seconds = constants.hour
eV_in_joules = constants.eV
# Prefix values
kilo = constants.kilo # 1000
mega = constants.mega # 1000000
Pitfalls
Sparse Array Indexing
# ❌ Wrong: DIA format doesn't support indexingfrom scipy import sparse
dia = sparse.dia_array([[1, 2], [3, 4]])
value = dia[0, 0] # Raises error# ✅ Right: Convert to CSR first
csr = dia.tocsr()
value = csr[0, 0]