package scipy

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
val get_py : string -> Py.Object.t

Get an attribute of this module as a Py.Object.t. This is useful to pass a Python function to another function.

val fftfreq : ?d:[ `F of float | `I of int | `Bool of bool | `S of string ] -> n:int -> unit -> [ `ArrayLike | `Ndarray | `Object ] Np.Obj.t

Return the Discrete Fourier Transform sample frequencies.

The returned float array `f` contains the frequency bin centers in cycles per unit of the sample spacing (with zero at the start). For instance, if the sample spacing is in seconds, then the frequency unit is cycles/second.

Given a window length `n` and a sample spacing `d`::

f = 0, 1, ..., n/2-1, -n/2, ..., -1 / (d*n) if n is even f = 0, 1, ..., (n-1)/2, -(n-1)/2, ..., -1 / (d*n) if n is odd

Parameters ---------- n : int Window length. d : scalar, optional Sample spacing (inverse of the sampling rate). Defaults to 1.

Returns ------- f : ndarray Array of length `n` containing the sample frequencies.

Examples -------- >>> signal = np.array(-2, 8, 6, 4, 1, 0, 3, 5, dtype=float) >>> fourier = np.fft.fft(signal) >>> n = signal.size >>> timestep = 0.1 >>> freq = np.fft.fftfreq(n, d=timestep) >>> freq array( 0. , 1.25, 2.5 , ..., -3.75, -2.5 , -1.25)

val fftshift : ?axes:[ `I of int | `Shape_tuple of Py.Object.t ] -> x:[> `Ndarray ] Np.Obj.t -> unit -> [ `ArrayLike | `Ndarray | `Object ] Np.Obj.t

Shift the zero-frequency component to the center of the spectrum.

This function swaps half-spaces for all axes listed (defaults to all). Note that ``y0`` is the Nyquist component only if ``len(x)`` is even.

Parameters ---------- x : array_like Input array. axes : int or shape tuple, optional Axes over which to shift. Default is None, which shifts all axes.

Returns ------- y : ndarray The shifted array.

See Also -------- ifftshift : The inverse of `fftshift`.

Examples -------- >>> freqs = np.fft.fftfreq(10, 0.1) >>> freqs array( 0., 1., 2., ..., -3., -2., -1.) >>> np.fft.fftshift(freqs) array(-5., -4., -3., -2., -1., 0., 1., 2., 3., 4.)

Shift the zero-frequency component only along the second axis:

>>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3) >>> freqs array([ 0., 1., 2.], [ 3., 4., -4.], [-3., -2., -1.]) >>> np.fft.fftshift(freqs, axes=(1,)) array([ 2., 0., 1.], [-4., 3., 4.], [-1., -3., -2.])

val ifftshift : ?axes:[ `I of int | `Shape_tuple of Py.Object.t ] -> x:[> `Ndarray ] Np.Obj.t -> unit -> [ `ArrayLike | `Ndarray | `Object ] Np.Obj.t

The inverse of `fftshift`. Although identical for even-length `x`, the functions differ by one sample for odd-length `x`.

Parameters ---------- x : array_like Input array. axes : int or shape tuple, optional Axes over which to calculate. Defaults to None, which shifts all axes.

Returns ------- y : ndarray The shifted array.

See Also -------- fftshift : Shift zero-frequency component to the center of the spectrum.

Examples -------- >>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3) >>> freqs array([ 0., 1., 2.], [ 3., 4., -4.], [-3., -2., -1.]) >>> np.fft.ifftshift(np.fft.fftshift(freqs)) array([ 0., 1., 2.], [ 3., 4., -4.], [-3., -2., -1.])

val next_fast_len : int -> int

Find the next fast size of input data to `fft`, for zero-padding, etc.

SciPy's FFTPACK has efficient functions for radix

, 3, 4, 5

, so this returns the next composite of the prime factors 2, 3, and 5 which is greater than or equal to `target`. (These are also known as 5-smooth numbers, regular numbers, or Hamming numbers.)

Parameters ---------- target : int Length to start searching from. Must be a positive integer.

Returns ------- out : int The first 5-smooth number greater than or equal to `target`.

Notes ----- .. versionadded:: 0.18.0

Examples -------- On a particular machine, an FFT of prime length takes 133 ms:

>>> from scipy import fftpack >>> min_len = 10007 # prime length is worst case for speed >>> a = np.random.randn(min_len) >>> b = fftpack.fft(a)

Zero-padding to the next 5-smooth length reduces computation time to 211 us, a speedup of 630 times:

>>> fftpack.helper.next_fast_len(min_len) 10125 >>> b = fftpack.fft(a, 10125)

Rounding up to the next power of 2 is not optimal, taking 367 us to compute, 1.7 times as long as the 5-smooth size:

>>> b = fftpack.fft(a, 16384)

val rfftfreq : ?d:[ `F of float | `I of int | `Bool of bool | `S of string ] -> n:int -> unit -> [ `ArrayLike | `Ndarray | `Object ] Np.Obj.t

DFT sample frequencies (for usage with rfft, irfft).

The returned float array contains the frequency bins in cycles/unit (with zero at the start) given a window length `n` and a sample spacing `d`::

f = 0,1,1,2,2,...,n/2-1,n/2-1,n/2/(d*n) if n is even f = 0,1,1,2,2,...,n/2-1,n/2-1,n/2,n/2/(d*n) if n is odd

Parameters ---------- n : int Window length. d : scalar, optional Sample spacing. Default is 1.

Returns ------- out : ndarray The array of length `n`, containing the sample frequencies.

Examples -------- >>> from scipy import fftpack >>> sig = np.array(-2, 8, 6, 4, 1, 0, 3, 5, dtype=float) >>> sig_fft = fftpack.rfft(sig) >>> n = sig_fft.size >>> timestep = 0.1 >>> freq = fftpack.rfftfreq(n, d=timestep) >>> freq array( 0. , 1.25, 1.25, 2.5 , 2.5 , 3.75, 3.75, 5. )

OCaml

Innovation. Community. Security.