SciPy
Solve optimization, statistics, signal processing, and linear algebra problems with SciPy recipes and ready-to-run code.
от clawic★ 23 звезды на GitHub
Установить SciPy в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Setup
On first use, read setup.md for guidance on how to help the user effectively.
When to Use
User needs scientific computing in Python: optimization, curve fitting, statistical tests, signal processing, interpolation, integration, or linear algebra. Agent provides working code, not theory.
Architecture
This skill is stateless — no persistent storage needed. All code runs in user's Python environment.
See memory-template.md for optional preference tracking.
Quick Reference
| Topic | File |
|---|---|
| Usage guidance | setup.md |
| Optional preferences | memory-template.md |
Core Rules
1. Working Code First
Every response includes runnable code. No pseudocode, no "implement this yourself".
# Always include imports
from scipy import optimize
import numpy as np
# Complete, working example
result = optimize.minimize(lambda x: x**2, x0=1.0)
print(f"Minimum at x={result.x[0]:.4f}")
2. Module Selection Guide
| Problem | Module | Key Function |
|---|---|---|
| Find minimum/maximum | scipy.optimize |
minimize, minimize_scalar |
| Curve fitting | scipy.optimize |
curve_fit |
| Root finding | scipy.optimize |
root, brentq, fsolve |
| Statistical tests | scipy.stats |
ttest_ind, chi2_contingency |
| Distributions | scipy.stats |
norm, poisson, expon |
| Filter signals | scipy.signal |
butter, filtfilt, savgol_filter |
| FFT | scipy.fft |
fft, ifft, fftfreq |
| Interpolation | scipy.interpolate |
interp1d, UnivariateSpline |
| Integration | scipy.integrate |
quad, solve_ivp |
| Linear algebra | scipy.linalg |
solve, eig, svd |
| Sparse matrices | scipy.sparse |
csr_matrix, linalg.spsolve |
| Spatial data | scipy.spatial |
KDTree, distance |
| Image processing | scipy.ndimage |
gaussian_filter, label |
3. Explain Key Parameters
When code uses non-obvious parameters, explain why:
# method='L-BFGS-B' for bounded optimization
# bounds prevent physically impossible values
result = optimize.minimize(
objective, x0,
method='L-BFGS-B',
bounds=[(0, None), (0, 100)] # x1 >= 0, 0 <= x2 <= 100
)
4. Validate Results
Always include sanity checks:
result = optimize.minimize(func, x0)
if not result.success:
print(f"⚠️ Optimization failed: {result.message}")
else:
print(f"✓ Converged in {result.nit} iterations")
5. NumPy Integration
SciPy builds on NumPy. Use vectorized operations:
# ✓ Vectorized (fast)
x = np.linspace(0, 10, 1000)
y = np.sin(x)
# ✗ Loop (slow)
y = [np.sin(xi) for xi in x]
Optimization Patterns
Minimize a Function
from scipy.optimize import minimize
import numpy as np
# Rosenbrock function (classic test)
def rosenbrock(x):
return sum(100*(x[1:]-x[:-1]**2)**2 + (1-x[:-1])**2)
x0 = np.array([0, 0])
result = minimize(rosenbrock, x0, method='BFGS')
print(f"Minimum at: {result.x}")
print(f"Function value: {result.fun}")
print(f"Converged: {result.success}")
Constrained Optimization
from scipy.optimize import minimize
# Minimize f(x,y) = x² + y² subject to x + y = 1
def objective(x):
return x[0]**2 + x[1]**2
def constraint(x):
return x[0] + x[1] - 1 # Must equal 0
result = minimize(
objective,
x0=[0.5, 0.5],
constraints={'type': 'eq', 'fun': constraint}
)
Curve Fitting
from scipy.optimize import curve_fit
import numpy as np
# Fit exponential decay
def model(t, a, tau):
return a * np.exp(-t / tau)
t_data = np.array([0, 1, 2, 3, 4, 5])
y_data = np.array([10, 6.1, 3.7, 2.2, 1.4, 0.8])
params, covariance = curve_fit(model, t_data, y_data)
a_fit, tau_fit = params
errors = np.sqrt(np.diag(covariance))
print(f"a = {a_fit:.2f} ± {errors[0]:.2f}")
print(f"τ = {tau_fit:.2f} ± {errors[1]:.2f}")
Statistics Patterns
Hypothesis Testing
from scipy import stats
# Compare two groups (independent t-test)
group_a = [23, 25, 28, 24, 26]
group_b = [30, 32, 29, 31, 33]
t_stat, p_value = stats.ttest_ind(group_a, group_b)
print(f"t = {t_stat:.3f}, p = {p_value:.4f}")
if p_value < 0.05:
print("✓ Significant difference (p < 0.05)")
else:
print("✗ No significant difference")
Distribution Fitting
from scipy import stats
import numpy as np
data = np.random.exponential(scale=2.0, size=1000)
# Fit exponential distribution
loc, scale = stats.expon.fit(data)
print(f"Fitted scale (λ⁻¹): {scale:.3f}")
# Test goodness of fit
ks_stat, ks_p = stats.kstest(data, 'expon', args=(loc, scale))
print(f"KS test: p = {ks_p:.4f}")
Confidence Intervals
from scipy import stats
import numpy as np
data = [2.3, 2.5, 2.1, 2.8, 2.4, 2.6, 2.2]
confidence = 0.95
mean = np.mean(data)
sem = stats.sem(data)
ci = stats.t.interval(confidence, len(data)-1, loc=mean, scale=sem)
print(f"Mean: {mean:.2f}")
print(f"95% CI: [{ci[0]:.2f}, {ci[1]:.2f}]")
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- _meta.json
- memory-template.md
- setup.md
FAQ
Что делает скилл SciPy?
Solve optimization, statistics, signal processing, and linear algebra problems with SciPy recipes and ready-to-run code.
Как установить скилл SciPy?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл SciPy запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…