# SciPy — Fundamental Algorithms for Scientific Computing > SciPy provides efficient numerical routines for optimization, integration, interpolation, linear algebra, signal processing, and statistics, all built on NumPy arrays. ## Install Save as a script file and run: # SciPy — Fundamental Algorithms for Scientific Computing ## Quick Use ```bash pip install scipy python -c " from scipy import optimize result = optimize.minimize(lambda x: (x-3)**2, x0=0) print(f'Minimum at x={result.x[0]:.2f}') " ``` ## Introduction SciPy is a core library in the Python scientific computing stack. It builds on NumPy to provide a collection of mathematical algorithms and convenience functions for optimization, integration, interpolation, eigenvalue problems, statistics, signal and image processing, and sparse matrix operations. ## What SciPy Does - Provides numerical optimization solvers (minimize, least_squares, linear_programming) - Implements numerical integration and ODE/PDE solvers - Offers sparse matrix representations and solvers for large-scale linear algebra - Includes signal processing tools (FFT, filtering, wavelets, spectral analysis) - Bundles statistical distributions, hypothesis tests, and descriptive statistics ## Architecture Overview SciPy is organized into subpackages, each focused on a domain: `scipy.optimize`, `scipy.linalg`, `scipy.sparse`, `scipy.signal`, `scipy.stats`, and others. Under the hood, most routines wrap battle-tested Fortran and C libraries (LAPACK, BLAS, FITPACK, QUADPACK, ODEPACK) via Cython or f2py bindings, giving Python access to decades of validated numerical code with near-native performance. ## Self-Hosting & Configuration - Install via `pip install scipy` or `conda install scipy` for optimized BLAS/LAPACK - Requires NumPy as a dependency; compatible with NumPy 1.x and 2.x - Build from source with `python -m pip install .` using Meson build system - Use `scipy.show_config()` to verify linked BLAS/LAPACK implementations - Pin versions in requirements.txt for reproducible scientific workflows ## Key Features - Over 20 optimization algorithms including global optimizers (differential_evolution, dual_annealing) - Sparse matrix support in CSR, CSC, COO, and other formats with efficient solvers - Spatial algorithms: KD-trees, Delaunay triangulation, convex hulls, Voronoi diagrams - Interpolation with splines (univariate, bivariate, N-dimensional) - Statistical distributions (over 100 continuous and discrete) with fitting and testing ## Comparison with Similar Tools - **NumPy** — provides arrays and basic linear algebra; SciPy adds advanced algorithms on top of NumPy - **MATLAB** — proprietary with similar capabilities; SciPy is free and integrates with the Python ecosystem - **Statsmodels** — deeper statistical modeling (regression, time series); SciPy covers broader numerical methods - **SymPy** — symbolic math; SciPy is purely numerical for fast floating-point computation - **scikit-learn** — machine learning algorithms; SciPy provides the underlying numerical building blocks ## FAQ **Q: What is the difference between NumPy and SciPy?** A: NumPy provides the array data structure and basic operations. SciPy builds on it with specialized algorithms for optimization, integration, statistics, and more. **Q: Does SciPy support GPU acceleration?** A: SciPy is CPU-only. For GPU-accelerated equivalents, consider CuPy which mirrors the SciPy API on NVIDIA GPUs. **Q: How do I choose an optimization algorithm?** A: Use `minimize` with method='L-BFGS-B' for smooth problems with bounds, 'Nelder-Mead' for derivative-free optimization, or 'trust-constr' for constrained problems. **Q: Is SciPy suitable for production use?** A: Yes. SciPy wraps proven numerical libraries and is used in production across scientific computing, engineering, and finance. ## Sources - https://github.com/scipy/scipy - https://scipy.org/ --- Source: https://tokrepo.com/en/workflows/c0268701-40a1-11f1-9bc6-00163e2b0d79 Author: Script Depot