Relationship between SciPy and NumPy

前端 未结 8 1801
清酒与你
清酒与你 2020-11-27 09:34

SciPy appears to provide most (but not all [1]) of NumPy\'s functions in its own namespace. In other words, if there\'s a function named numpy.foo, there\'s alm

8条回答
  •  余生分开走
    2020-11-27 10:03

    From Lectures on 'Quantitative Economics'

    SciPy is a package that contains various tools that are built on top of NumPy, using its array data type and related functionality

    In fact, when we import SciPy we also get NumPy, as can be seen from the SciPy initialization file

    # Import numpy symbols to scipy name space
    import numpy as _num
    linalg = None
    from numpy import *
    from numpy.random import rand, randn
    from numpy.fft import fft, ifft
    from numpy.lib.scimath import *
    
    __all__  = []
    __all__ += _num.__all__
    __all__ += ['randn', 'rand', 'fft', 'ifft']
    
    del _num
    # Remove the linalg imported from numpy so that the scipy.linalg package can be
    # imported.
    del linalg
    __all__.remove('linalg')
    

    However, it’s more common and better practice to use NumPy functionality explicitly

    import numpy as np
    
    a = np.identity(3)
    

    What is useful in SciPy is the functionality in its subpackages

    • scipy.optimize, scipy.integrate, scipy.stats, etc.

提交回复
热议问题