bundles / scipy 1.17.1 / scipy / fft / _realtransforms / dst
_Function
scipy.fft._realtransforms:dst
Signature
def dst ( x , type = 2 , n = None , axis = -1 , norm = None , overwrite_x = False , workers = None , orthogonalize = None ) Summary
Return the Discrete Sine Transform of arbitrary type sequence x.
Parameters
x: array_likeThe input array.
type: {1, 2, 3, 4}, optionalType of the DST (see Notes). Default type is 2.
n: int, optionalLength of the transform. If
n < x.shape[axis],xis truncated. Ifn > x.shape[axis],xis zero-padded. The default results inn = x.shape[axis].axis: int, optionalAxis along which the dst is computed; the default is over the last axis (i.e.,
axis=-1).norm: {"backward", "ortho", "forward"}, optionalNormalization mode (see Notes). Default is "backward".
overwrite_x: bool, optionalIf True, the contents of
xcan be destroyed; the default is False.workers: int, optionalMaximum number of workers to use for parallel computation. If negative, the value wraps around from
os.cpu_count(). See fft for more details.orthogonalize: bool, optionalWhether to use the orthogonalized DST variant (see Notes). Defaults to
Truewhennorm="ortho"andFalseotherwise.
Returns
dst: ndarray of realsThe transformed input array.
Notes
For norm="ortho" both the dst and idst are scaled by the same overall factor in both directions. By default, the transform is also orthogonalized which for types 2 and 3 means the transform definition is modified to give orthogonality of the DST matrix (see below).
For norm="backward", there is no scaling on the dst and the idst is scaled by 1/N where N is the "logical" size of the DST.
There are, theoretically, 8 types of the DST for different combinations of even/odd boundary conditions and boundary off sets [1], only the first 4 types are implemented in SciPy.
Type I
There are several definitions of the DST-I; we use the following for norm="backward". DST-I assumes the input is odd around and .
Note that the DST-I is only supported for input size > 1. The (unnormalized) DST-I is its own inverse, up to a factor . The orthonormalized DST-I is exactly its own inverse.
orthogonalize has no effect here, as the DST-I matrix is already orthogonal up to a scale factor of 2N.
Type II
There are several definitions of the DST-II; we use the following for norm="backward". DST-II assumes the input is odd around and ; the output is odd around and even around
If orthogonalize=True, y[-1] is divided which, when combined with norm="ortho", makes the corresponding matrix of coefficients orthonormal (O @ O.T = np.eye(N)).
Type III
There are several definitions of the DST-III, we use the following (for norm="backward"). DST-III assumes the input is odd around and even around
If orthogonalize=True, x[-1] is multiplied by which, when combined with norm="ortho", makes the corresponding matrix of coefficients orthonormal (O @ O.T = np.eye(N)).
The (unnormalized) DST-III is the inverse of the (unnormalized) DST-II, up to a factor . The orthonormalized DST-III is exactly the inverse of the orthonormalized DST-II.
Type IV
There are several definitions of the DST-IV, we use the following (for norm="backward"). DST-IV assumes the input is odd around and even around
orthogonalize has no effect here, as the DST-IV matrix is already orthogonal up to a scale factor of 2N.
The (unnormalized) DST-IV is its own inverse, up to a factor . The orthonormalized DST-IV is exactly its own inverse.
Array API Standard Support
dst has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ⛔ PyTorch ✅ ⛔ JAX ⛔ ⛔ Dask ⚠️ computes graph n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
Compute the DST of a simple 1D array:import numpy as np from scipy.fft import dst x = np.array([1, -1, 1, -1]) dst(x, type=2)✓
See also
- idst
Inverse DST
Aliases
-
scipy.fft.dst