Official abbreviation for: import scipy as sp/sc

后端 未结 2 1585
萌比男神i
萌比男神i 2020-12-15 03:40

I\'ve seen both:

import scipy as sp

and:

import scipy as sc

Is there an official preference listed anywh

相关标签:
2条回答
  • 2020-12-15 04:19

    As cel pointed out, the API documentation recommends to not import scipy, but to import specific modules from scipy:

    The scipy namespace itself only contains functions imported from numpy. These functions still exist for backwards compatibility, but should be imported from numpy directly.

    Therefore, importing only the scipy base package does only provide numpy content, which could be imported from numpy directly.

    If somebody still wants the main package, sp for Scipy would be convenient as np usially is used for NumPy.

    0 讨论(0)
  • 2020-12-15 04:36

    The "official" answer, according to the Scipy documentation, is that there is really no reason to ever

    import scipy
    

    since all of the interesting functions in Scipy are actually located in the submodules, which are not automatically imported. Therefore, the recommended method is to use

    from scipy import fftpack
    from scipy import integrate
    

    then, functions can be called with

    fftpack.fft()
    

    Personally, I always use

    import scipy.fftpack
    

    and live with the slightly longer function call

    scipy.fftpack.fft(data)
    

    This way I know where the functions are coming from.

    0 讨论(0)
提交回复
热议问题