scipy-python

Write and verify SciPy optimization, root-finding, and sparse linear algebra code with explicit convergence checks.

Updated Aug 12, 2026
One-click install
npx skills add https://github.com/schattenspiegel/skill-foundry-skills --skill scipy-python-schattenspiegel
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: scipy-python
Source: https://github.com/schattenspiegel/skill-foundry-skills/tree/main/skills/scipy-python
Command: npx skills add https://github.com/schattenspiegel/skill-foundry-skills --skill scipy-python-schattenspiegel

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires numpy, scipy, pytest, and includes references (resource) components.

What problem does it solve? Numerical Python code often fails silently: optimizers return unconverged vectors, root solvers miss brackets, and sparse matrices get accidentally densified. This Skill enforces explicit execution contracts, residual verification, and failure routing so SciPy results are provably correct rather than assumed correct. ## Core Features & Use Cases - Solver selection guidance: Choose optimization, root-finding, integration, interpolation, sparse, signal, spatial, or statistical routines based on smoothness, bounds, derivative availability, and sparsity. - Evaluated solution recipes: Anchored implementations for bounded minimization with gradient checks, bracketed scalar root solving, and sparse linear solves with residual guards, each paired with a verification test. - Verification and failure routing: Classify failures as input-contract, environment, execution, or invariant issues, and reject nonconvergence, nonfinite outputs, and excessive residuals before declaring completion. - Use Case: When debugging a scipy.optimize.minimize call that returns a result without converging, the Skill directs you to check the success flag, verify the gradient residual independently, and scale tolerances from the application's units. ## Quick Start Ask the assistant to solve a bounded least-squares problem with scipy.optimize.minimize and verify the optimum with an independent residual check.

Frequently Asked Questions about scipy-python

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I verify a scipy.optimize.minimize result actually converged?▼

Check the result.success flag, confirm the objective value is finite, and independently evaluate the gradient norm at the solution against a tolerance. A returned vector alone is not proof of convergence; raise an error with result.message when any check fails.

How to solve a scalar root with scipy root_scalar?▼

Use root_scalar with method='brentq' and a sign-changing bracket, plus an explicit xtol. After solving, verify result.converged and check that the residual abs(f(root)) stays within a scaled tolerance before returning the value.

Which sparse matrix format should I use in SciPy?▼

Choose CSR for row slicing and matrix-vector products, CSC for column operations and spsolve, and COO for incremental construction. Convert deliberately and avoid accidental dense conversion in production-size code paths.

When should I not use SciPy for numerical work?▼

Avoid SciPy for symbolic algebra, which belongs in SymPy, and for arbitrary-precision arithmetic, which needs mpmath or the decimal module. Generic NumPy array manipulation alone also does not require SciPy routines.

Why does my scipy sparse solve give wrong results?▼

Common causes are shape mismatches between the operator and right-hand side, nonfinite input values, or silent densification changing semantics. Validate dimensions and finiteness up front, then check the relative residual norm of A*x - b against a scaled tolerance.