Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2SciPy: A scientific computing package for Python 

3================================================ 

4 

5Documentation is available in the docstrings and 

6online at https://docs.scipy.org. 

7 

8Contents 

9-------- 

10SciPy imports all the functions from the NumPy namespace, and in 

11addition provides: 

12 

13Subpackages 

14----------- 

15Using any of these subpackages requires an explicit import. For example, 

16``import scipy.cluster``. 

17 

18:: 

19 

20 cluster --- Vector Quantization / Kmeans 

21 fft --- Discrete Fourier transforms 

22 fftpack --- Legacy discrete Fourier transforms 

23 integrate --- Integration routines 

24 interpolate --- Interpolation Tools 

25 io --- Data input and output 

26 linalg --- Linear algebra routines 

27 linalg.blas --- Wrappers to BLAS library 

28 linalg.lapack --- Wrappers to LAPACK library 

29 misc --- Various utilities that don't have 

30 another home. 

31 ndimage --- N-D image package 

32 odr --- Orthogonal Distance Regression 

33 optimize --- Optimization Tools 

34 signal --- Signal Processing Tools 

35 signal.windows --- Window functions 

36 sparse --- Sparse Matrices 

37 sparse.linalg --- Sparse Linear Algebra 

38 sparse.linalg.dsolve --- Linear Solvers 

39 sparse.linalg.dsolve.umfpack --- :Interface to the UMFPACK library: 

40 Conjugate Gradient Method (LOBPCG) 

41 sparse.linalg.eigen --- Sparse Eigenvalue Solvers 

42 sparse.linalg.eigen.lobpcg --- Locally Optimal Block Preconditioned 

43 Conjugate Gradient Method (LOBPCG) 

44 spatial --- Spatial data structures and algorithms 

45 special --- Special functions 

46 stats --- Statistical Functions 

47 

48Utility tools 

49------------- 

50:: 

51 

52 test --- Run scipy unittests 

53 show_config --- Show scipy build configuration 

54 show_numpy_config --- Show numpy build configuration 

55 __version__ --- SciPy version string 

56 __numpy_version__ --- Numpy version string 

57 

58""" 

59__all__ = ['test'] 

60 

61from numpy import show_config as show_numpy_config 

62if show_numpy_config is None: 

63 raise ImportError( 

64 "Cannot import SciPy when running from NumPy source directory.") 

65from numpy import __version__ as __numpy_version__ 

66 

67# Import numpy symbols to scipy name space (DEPRECATED) 

68from ._lib.deprecation import _deprecated 

69import numpy as _num 

70linalg = None 

71_msg = ('scipy.{0} is deprecated and will be removed in SciPy 2.0.0, ' 

72 'use numpy.{0} instead') 

73# deprecate callable objects, skipping classes 

74for _key in _num.__all__: 

75 _fun = getattr(_num, _key) 

76 if callable(_fun) and not isinstance(_fun, type): 

77 _fun = _deprecated(_msg.format(_key))(_fun) 

78 globals()[_key] = _fun 

79from numpy.random import rand, randn 

80_msg = ('scipy.{0} is deprecated and will be removed in SciPy 2.0.0, ' 

81 'use numpy.random.{0} instead') 

82rand = _deprecated(_msg.format('rand'))(rand) 

83randn = _deprecated(_msg.format('randn'))(randn) 

84from numpy.fft import fft, ifft 

85# fft is especially problematic, so we deprecate it with a shorter window 

86fft_msg = ('Using scipy.fft as a function is deprecated and will be ' 

87 'removed in SciPy 1.5.0, use scipy.fft.fft instead.') 

88# for wrapping in scipy.fft.__call__, so the stacklevel is one off from the 

89# usual (2) 

90_dep_fft = _deprecated(fft_msg, stacklevel=3)(fft) 

91fft = _deprecated(fft_msg)(fft) 

92ifft = _deprecated('scipy.ifft is deprecated and will be removed in SciPy ' 

93 '2.0.0, use scipy.fft.ifft instead')(ifft) 

94import numpy.lib.scimath as _sci 

95_msg = ('scipy.{0} is deprecated and will be removed in SciPy 2.0.0, ' 

96 'use numpy.lib.scimath.{0} instead') 

97for _key in _sci.__all__: 

98 _fun = getattr(_sci, _key) 

99 if callable(_fun): 

100 _fun = _deprecated(_msg.format(_key))(_fun) 

101 globals()[_key] = _fun 

102 

103# Allow distributors to run custom init code 

104from . import _distributor_init 

105 

106__all__ += _num.__all__ 

107__all__ += ['randn', 'rand', 'fft', 'ifft'] 

108 

109del _num 

110# Remove the linalg imported from NumPy so that the scipy.linalg package can be 

111# imported. 

112del linalg 

113__all__.remove('linalg') 

114 

115# We first need to detect if we're being called as part of the SciPy 

116# setup procedure itself in a reliable manner. 

117try: 

118 __SCIPY_SETUP__ 

119except NameError: 

120 __SCIPY_SETUP__ = False 

121 

122 

123if __SCIPY_SETUP__: 

124 import sys as _sys 

125 _sys.stderr.write('Running from SciPy source directory.\n') 

126 del _sys 

127else: 

128 try: 

129 from scipy.__config__ import show as show_config 

130 except ImportError: 

131 msg = """Error importing SciPy: you cannot import SciPy while 

132 being in scipy source directory; please exit the SciPy source 

133 tree first and relaunch your Python interpreter.""" 

134 raise ImportError(msg) 

135 

136 from scipy.version import version as __version__ 

137 from scipy._lib import _pep440 

138 if _pep440.parse(__numpy_version__) < _pep440.Version('1.14.5'): 

139 import warnings 

140 warnings.warn("NumPy 1.14.5 or above is required for this version of " 

141 "SciPy (detected version %s)" % __numpy_version__, 

142 UserWarning) 

143 

144 del _pep440 

145 

146 from scipy._lib._ccallback import LowLevelCallable 

147 

148 from scipy._lib._testutils import PytestTester 

149 test = PytestTester(__name__) 

150 del PytestTester 

151 

152 # This makes "from scipy import fft" return scipy.fft, not np.fft 

153 del fft 

154 from . import fft