agentleFS
MindrallyMindrally/skills/scipy-best-practices/SKILL.md

scipy-best-practices

Skill275 starsChanged 54 days agoApache-2.0View on GitHub

Best practices for SciPy scientific computing, optimization, signal processing, and statistical analysis in Python

The file

Show its rules and text

We split this skill into the rules it gives an agent

38 rules. About 0 are common, 14 are distinctive, and 24 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈14

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 24

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Write concise, technical Python code with accurate SciPy examples

    line 15
  2. Distinctive:

    Use functional programming patterns for mathematical operations

    line 17
  3. Distinctive:

    Prefer vectorized operations over explicit loops

    line 18
  4. Distinctive:

    Use descriptive variable names reflecting scientific context

    line 19
  5. Distinctive:

    Follow PEP 8 style guidelines

    line 20
  6. Very specific:

    Use scipy.optimize.minimize() for general-purpose optimization

    line 24
  7. Very specific:

    Use scipy.optimize.curve_fit() for nonlinear least squares fitting

    line 31
  8. Very specific:

    Use scipy.optimize.root() for finding roots of equations

    line 32
  9. Very specific:

    Prefer scipy.linalg over numpy.linalg for additional functionality

    line 36
  10. Very specific:

    Use scipy.linalg.solve() instead of computing matrix inverse

    line 37
  11. Very specific:

    Use scipy.linalg.lu_factor() and lu_solve() for multiple right-hand sides

    line 39
  12. Very specific:

    Use sparse matrix solvers from scipy.sparse.linalg for large sparse systems

    line 40
  13. Distinctive:

    Use distribution objects for probability calculations

    line 44
  14. Very specific:

    Use hypothesis testing functions: ttest_ind(), chi2_contingency(), mannwhitneyu()

    line 46
  15. Very specific:

    Use .fit() for parameter estimation from data

    line 48
  16. Very specific:

    Use scipy.interpolate.interp1d() for 1D interpolation

    line 52
  17. Very specific:

    Use scipy.interpolate.griddata() for scattered data interpolation

    line 53
  18. Very specific:

    Use spline functions for smooth interpolation: UnivariateSpline, BSpline

    line 55
  19. Very specific:

    Consider RegularGridInterpolator for regular grid data

    line 56
  20. Very specific:

    Use scipy.integrate.quad() for single integrals

    line 60
  21. Very specific:

    Use scipy.integrate.dblquad(), tplquad() for multiple integrals

    line 61
  22. Very specific:

    Use scipy.integrate.solve_ivp() for ordinary differential equations

    line 62
  23. Very specific:

    Use scipy.signal.butter(), cheby1(), ellip() for filter design

    line 68
  24. Very specific:

    Use scipy.signal.welch() for power spectral density estimation

    line 70
  25. Very specific:

    Use scipy.signal.find_peaks() for peak detection

    line 71
  26. Distinctive:

    Use appropriate sparse format for your use case:

    line 76
  27. Very specific:

    Use scipy.sparse.linalg solvers for sparse linear systems

    line 82
  28. Very specific:

    Use appropriate data types (float64 for precision, float32 for memory)

    line 86
  29. Distinctive:

    Use in-place operations when available

    line 89
  30. Distinctive:

    Check convergence status of optimization routines

    line 93
  31. Distinctive:

    Use appropriate tolerances for convergence criteria

    line 96
  32. Distinctive:

    Test against known analytical solutions

    line 100
  33. Very specific:

    Use np.testing.assert_allclose() for numerical comparisons

    line 101
  34. Distinctive:

    Test edge cases and boundary conditions

    line 102
  35. Distinctive:

    Verify conservation laws and invariants

    line 103
  36. Very specific:

    Import specific submodules: from scipy import optimize, stats, linalg

    line 107
  37. Very specific:

    Use snake_case for variables and functions

    line 108
  38. Distinctive:

    Document algorithm choices and parameters

    line 109

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

SciPy Best Practices

Expert guidelines for SciPy development, focusing on scientific computing, optimization, signal processing, and statistical analysis.

Code Style and Structure

  • Write concise, technical Python code with accurate SciPy examples
  • Prioritize numerical accuracy and computational efficiency
  • Use functional programming patterns for mathematical operations
  • Prefer vectorized operations over explicit loops
  • Use descriptive variable names reflecting scientific context
  • Follow PEP 8 style guidelines

scipy.optimize - Optimization

  • Use scipy.optimize.minimize() for general-purpose optimization
  • Choose appropriate method based on problem characteristics:
    • 'BFGS' for smooth, unconstrained problems
    • 'L-BFGS-B' for bounded problems
    • 'SLSQP' for constrained optimization
    • 'Nelder-Mead' for non-differentiable functions
  • Provide gradients when available for faster convergence
  • Use scipy.optimize.curve_fit() for nonlinear least squares fitting
  • Use scipy.optimize.root() for finding roots of equations

scipy.linalg - Linear Algebra

  • Prefer scipy.linalg over numpy.linalg for additional functionality
  • Use scipy.linalg.solve() instead of computing matrix inverse
  • Leverage specialized solvers for structured matrices (banded, triangular)
  • Use scipy.linalg.lu_factor() and lu_solve() for multiple right-hand sides
  • Use sparse matrix solvers from scipy.sparse.linalg for large sparse systems

scipy.stats - Statistics

  • Use distribution objects for probability calculations
  • Leverage scipy.stats.describe() for summary statistics
  • Use hypothesis testing functions: ttest_ind(), chi2_contingency(), mannwhitneyu()
  • Generate random samples with .rvs() method on distributions
  • Use .fit() for parameter estimation from data

scipy.interpolate - Interpolation

  • Use scipy.interpolate.interp1d() for 1D interpolation
  • Use scipy.interpolate.griddata() for scattered data interpolation
  • Choose appropriate interpolation method: 'linear', 'cubic', 'nearest'
  • Use spline functions for smooth interpolation: UnivariateSpline, BSpline
  • Consider RegularGridInterpolator for regular grid data

scipy.integrate - Integration

  • Use scipy.integrate.quad() for single integrals
  • Use scipy.integrate.dblquad(), tplquad() for multiple integrals
  • Use scipy.integrate.solve_ivp() for ordinary differential equations
  • Choose appropriate ODE method: 'RK45', 'BDF', 'LSODA'
  • Provide Jacobian for stiff systems to improve performance

scipy.signal - Signal Processing

  • Use scipy.signal.butter(), cheby1(), ellip() for filter design
  • Apply filters with scipy.signal.filtfilt() for zero-phase filtering
  • Use scipy.signal.welch() for power spectral density estimation
  • Use scipy.signal.find_peaks() for peak detection
  • Leverage scipy.signal.convolve() and correlate() for convolution

scipy.sparse - Sparse Matrices

  • Use appropriate sparse format for your use case:
    • csr_matrix for efficient row slicing and matrix-vector products
    • csc_matrix for efficient column slicing
    • coo_matrix for constructing sparse matrices
    • lil_matrix for incremental construction
  • Convert to optimal format before operations
  • Use scipy.sparse.linalg solvers for sparse linear systems

Performance Optimization

  • Use appropriate data types (float64 for precision, float32 for memory)
  • Leverage BLAS/LAPACK through SciPy for optimized linear algebra
  • Pre-allocate arrays when possible
  • Use in-place operations when available

Error Handling and Validation

  • Check convergence status of optimization routines
  • Validate numerical results for reasonableness
  • Handle ill-conditioned problems gracefully
  • Use appropriate tolerances for convergence criteria

Testing Scientific Code

  • Test against known analytical solutions
  • Use np.testing.assert_allclose() for numerical comparisons
  • Test edge cases and boundary conditions
  • Verify conservation laws and invariants

Key Conventions

  • Import specific submodules: from scipy import optimize, stats, linalg
  • Use snake_case for variables and functions
  • Document algorithm choices and parameters
  • Include convergence diagnostics in output

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.