How to import Scipy library and submodules

SciPy also known as "Sigh Pi." Is a python based open source library, the library provides many ready-to-use functionalities for scientific and mathematical computing.

Before you start with SciPy, make sure you have good understanding of numpy array, because in scipy example we will be using different type of array from numpy library, here is the numpy tutorial with example to make you familiar with numpy array functions

Install SciPy

You can install SciPy in your local python environment using command pip install SciPy.

Python3 -m pip install SciPy
What is SciPy?

SciPy library provides many sub packages to solve many Scientific Computation related issues, there are many built-in function which are easy to use, SciPy library is widely accepted scientific library like GNU Scientific Library written in C.

SciPy has wide range of sub-modules, SciPy builds on top of NumPy, below are some of the popular SciPy modules

All modules and sub-modules that comes under scipy namespaces, are public. importing scipy functions from sub-modules is considered as best practice like example below.

from scipy import optimize
result = optimize.curve_fit(...)

Sometimes you may give one level deeper reference to access the scipy api function like scipy.stats.

from scipy.stats import distributions
distributions.lomax(...)

As a beginner, you should start exploring following scipy library.

  • Basic functions
  • Special functions (scipy.special)
  • File IO

    Unlike importing other modules, IO module is an exception, we can import IO module like example below.

    from scipy import integrate
    import scipy.io as spio
    

    Because IO is also name of another module in the Python stdlib.

  • Spatial data structures and algorithms (scipy.spatial)

    scipy.spatial can compute triangulations, curved set of points etc, this is how we can import object from scipy.spatial library.

    from scipy.spatial import Delaunay
    points = np.array([[0, 0], [0, 1.1], [1, 0], [1, 1]])
    tri = Delaunay(points)
    
  • Linear Algebra (scipy.linalg)

    When working with numpy array, we need to add the numpy reference separately.

    Linalg module is for liner algebra, this module is also available under numpy namespace, so scipy.linalg has all the functionalities of numpy.linalg, and more advanced functions.

    import numpy as np
    from scipy import linalg
    A = np.array([[1,2],[3,4]])
    linalg.inv(A)
    
  • Statistics (scipy.stats)

    scipy.stats module contains correlation functions and statistical tests etc, it has a large number of probability distributions and frequency statistics.

    We can import scipy stats package as import stats, also we can directly import deeper objects with one level deeper reference.

    from scipy import stats
    from scipy.stats import norm
    
  • Multidimensional image processing (scipy.ndimage)
  • Signal Processing (scipy.signal)

You should join scipy community to learn effectively, you get to know about latest trends and how people using scipy functions for developing real-time application.

You may be interested in following tutorials

 
Import scipy library
Learn python programming with free python coding tutorials.
Other Popular Tutorials
scipy example
Python programming examples | Join Python Course