onebone.feature

onebone.feature.correlations

Signal correlation features.

onebone.feature.correlations.phase_alignment(y: ndarray, fs: Union[int, float]) Tuple[ndarray, ndarray]

Compute phase alignment(PA) of a set of 1D signals

\[{PA_{f} = \mid {1 \over n} \sum_j{e^{iw_{j,f}}} \mid }\]

Where \(PA_{f}\) is phase alignment value on frequency \(f\), \(n\) is the number of signals, and \(j\) is the index of each signals. \(w_{j, f}\) denotes phase of signal \(j\) at frequency \(f\).

This function computes mean vector of unit phase vectors of 1D signals. This process is repeated for every frequency unit.

Parameters
  • y (numpy.ndarray of shape (n, signal_length)) – n denotes the number of signals, and each signal shold be 1D time domain.

  • fs (int or float) – Sample rate. The sample rate is the number of samples per unit time.

Returns

  • freq (numpy.ndarray) – Frequency array

  • phase_alignment (numpy.ndarray) – Phase alignment value of each frequency

Examples

>>> fs, n = 1000.0, 1000
>>> x = np.linspace(0.0, n  / fs, n, endpoint=False)
>>> signal = 3 * np.sin(50. * np.pi * x) + 2 * np.sin(80.0 * np.pi * x)
>>> y = np.array([signal + np.random.uniform(low=-1, high=1, size=(n,)) for i in range(10)])
>>> freq, pa_result = phase_alignment(y, fs)

onebone.feature.frequency

Frequency domain feature.

onebone.feature.frequency.mdf(amp: ndarray, fs: Union[int, float] = 1, freq_range: Optional[Tuple] = None, axis: int = -1, keepdims: bool = False) float

Compute the median frequency.

\[{\sum_{j=1}^{MDF} A_{j} = \sum_{j=MDF}^{M} A_{j} = {1 \over 2}\sum_{j=1}^M P_{j}}^{[1]}\]

Where \(A_{j}\) is the amplitude value of spectrum at the frequency bin \(j\), and \(M\) is the length of frequency bin.

Parameters
  • amp (numpy.ndarray of shape (signal_length,), (n, signal_length)) – The amplitudes of a spectrum of time-domain signals.

  • fs (int or float, default=1) – Sample rate. The sample rate is the number of samples per unit time. If fs is 1, then mdf is the normalized frequency; (0 ~ 1).

  • freq_range (tuple, default=None) – Frequency range, specified as a two-element tuple of real values. If freq_range is None, then mdf uses the entire bandwidth of the input signal. That is, freq_range is (0, fs / 2).

  • axis (int, default=-1) – Axis along which mdf is performed. The default, axis`=-1, will calculate the `mdf along last axis of x. If axis is negative, it counts from the last to the first axis.

  • keepdims (bool, default=False) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one.

Returns

mdf (float or numpy.ndarray) – Median frequency. If fs is 1, then mdf has units of cycle/sample. But, if you specify the fs, then mdf has the same units as fs. E.g. cycle/sec.

References

1

Angkoon Phinyomark, Sirinee Thongpanja, Huosheng Hu, Pornchai Phukpattaranont and Chusak Limsakul (October 17th 2012). The Usefulness of Mean and Median Frequencies in Electromyography Analysis, Computational Intelligence in Electromyography Analysis - A Perspective on Current Applications and Future Challenges, Ganesh R. Naik, IntechOpen, DOI: 10.5772/50639. Available from: https://www.intechopen.com/chapters/40123

Examples

>>> import numpy as np
>>> fs = 100
>>> t = np.arange(0, 1, 1 / fs)
>>> x1 = np.sin(2 * np.pi * 10 * t)
>>> x2 = np.sin(2 * np.pi * 20 * t)
>>> x3 = np.sin(2 * np.pi * 30 * t)
>>> x = x1 + x2 + x3
>>> amp = np.abs(np.fft.fft(x))
>>> mdf(amp, fs)
20
onebone.feature.frequency.mnf(amp: ndarray, fs: Union[int, float] = 1, freq_range: Optional[Tuple] = None, axis: int = -1, keepdims: bool = False) Union[float, ndarray]

Compute the mean frequency.

\[{MNF = {\sum_{j=1}^M f_{j}A_{j} \over \sum_{j=1}^M A_{j}}}^{[1]}\]

Where \(f_{j}\) is the frequency value of spectrum at the bin \(j\), \(A_{j}\) is the amplitude value of spectrum at the frequency bin \(j\), and \(M\) is the length of frequency bin.

Parameters
  • amp (numpy.ndarray of shape (signal_length,), (n, signal_length)) – The amplitudes of a spectrum of time-domain signals.

  • fs (int or float, default=1) – Sample rate. The sample rate is the number of samples per unit time. If fs is 1, then mnf is the normalized frequency; (0 ~ 1).

  • freq_range (tuple, default=None) – Frequency range, specified as a two-element tuple of real values. If freq_range is None, then mnf uses the entire bandwidth of the input signal. That is, freq_range is (0, fs / 2).

  • axis (int, default=-1) – Axis along which mnf is performed. The default, axis`=-1, will calculate the `mnf along last axis of x. If axis is negative, it counts from the last to the first axis.

  • keepdims (bool, default=False) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one.

Returns

mnf (float or numpy.ndarray) – Mean frequency. If fs is 1, then mnf has units of cycle/sample. But, if you specify the fs, then mnf has the same units as fs. E.g. cycle/sec.

References

1

Angkoon Phinyomark, Sirinee Thongpanja, Huosheng Hu, Pornchai Phukpattaranont and Chusak Limsakul (October 17th 2012). The Usefulness of Mean and Median Frequencies in Electromyography Analysis, Computational Intelligence in Electromyography Analysis - A Perspective on Current Applications and Future Challenges, Ganesh R. Naik, IntechOpen, DOI: 10.5772/50639. Available from: https://www.intechopen.com/chapters/40123

Examples

>>> import numpy as np
>>> fs = 100
>>> t = np.arange(0, 1, 1 / fs)
>>> x1 = np.sin(2 * np.pi * 10 * t)
>>> x2 = np.sin(2 * np.pi * 20 * t)
>>> x3 = np.sin(2 * np.pi * 30 * t)
>>> x = x1 + x2 + x3
>>> amp = np.abs(np.fft.fft(x))
>>> mnf(amp, fs)
20
onebone.feature.frequency.vcf(amp: ndarray, fs: Union[int, float] = 1, freq_range: Optional[Tuple] = None, axis: int = -1, keepdims: bool = False) float

Compute the variance of central frequency(mean frequency).

\[{VCF = {1 \over \sum_{j=1}^M A_{j}}{\sum_{j=1}^M A_{j}(f_{j} - MNF)^2}}^{[1]}\]

Where \(f_{j}\) is the frequency value of spectrum at the bin \(j\), \(A_{j}\) is the amplitude value of spectrum at the frequency bin \(j\), \(M\) is the length of frequency bin, \(MNF\) is the mean frequency.

Parameters
  • amp (numpy.ndarray of shape (signal_length,), (n, signal_length)) – The amplitudes of a spectrum of time-domain signals.

  • fs (int or float, default=1) – Sample rate. The sample rate is the number of samples per unit time. If fs is 1, then vcf is the normalized frequency; (0 ~ 1).

  • freq_range (tuple, default=None) – Frequency range, specified as a two-element tuple of real values. If freq_range is None, then vcf uses the entire bandwidth of the input signal. That is, freq_range is (0, fs / 2).

  • axis (int, default=-1) – Axis along which vcf is performed. The default, axis`=-1, will calculate the `vcf along last axis of x. If axis is negative, it counts from the last to the first axis.

  • keepdims (bool, default=False) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one.

Returns

vcf (float or numpy.ndarray) – Median frequency. If fs is 1, then vcf has units of cycle/sample. But, if you specify the fs, then vcf has the same units as fs. E.g. cycle/sec.

References

1

Angkoon Phinyomark, Sirinee Thongpanja, Huosheng Hu, Pornchai Phukpattaranont and Chusak Limsakul (October 17th 2012). The Usefulness of Mean and Median Frequencies in Electromyography Analysis, Computational Intelligence in Electromyography Analysis - A Perspective on Current Applications and Future Challenges, Ganesh R. Naik, IntechOpen, DOI: 10.5772/50639. Available from: https://www.intechopen.com/chapters/40123

Examples

>>> import numpy as np
>>> fs = 100
>>> t = np.arange(0, 1, 1 / fs)
>>> x1 = np.sin(2 * np.pi * 10 * t)
>>> x2 = np.sin(2 * np.pi * 20 * t)
>>> x3 = np.sin(2 * np.pi * 30 * t)
>>> x = x1 + x2 + x3
>>> amp = np.abs(np.fft.fft(x))
>>> vcf(x, fs)
66.666

onebone.feature.gear

Condition metrics for gear.

onebone.feature.gear.na4(x_tsa: ndarray, prev_info: Tuple[int, float], fs: Union[int, float], rpm: float, freq_list: Optional[Tuple[float]] = None, n_harmonics: int = 2) Tuple[float, Tuple[int, float]]

Calculate NA4 metric.

NA4 indicates the onset of damage and continues to react to the damage as it spreads and increases in magnitude.

\[{NA4 = {N\sum_{i=1}^N (r_{i}-\bar{r})^4 \over \left\{\frac{1}{M} \sum_{j=1}^M \left[\sum_{i=1}^N (r_{ij}-\bar{r_j})^2\right] \right\}^2} = {({\mu}_4)_M \over {\frac{1}{M}\sum_{j=1}^M ({\mu}_2)_j}}}^{[1]}\]

Where \(r\) is residual signal, \(\bar{r}\) is mean value of residual signal, \(N\) is total number of data points in time record, \(M\) is current time record in run ensemble, \(i\) is data point number in time record, \(j\) is time record number in run ensemble, \({\mu}_2\) is the 2th central moment of \(r\), and \({\mu}_4\) is the 4th central moment of \(r\).

Parameters
  • x (numpy.ndarray of shape (length of x,)) – Time-synchronous-averaged signal (recommended)

  • prev_info (tuple of (int, float)) – The information for the ‘previous time record number’ in run ensemble. The first element of prev_info is the ‘previous time record number’(M-1). The second element of prev_info is the average of each 2th central moment of (M-1) previous residual signals. If the current time record number is 1, the prev_info is (0, 0).

  • fs (int or float) – Sampling rate

  • rpm (float) – Revolution per minute. The unit of ‘rpm’ is ‘rev/min’.

  • freq_list (None or tuple of floats, default=None) – The frequencies of gear-meshing components. They are filtered from the ‘x’ signal.

  • n_harmonics (int, default=2) – A positive integer specifying the number of shaft and gear meshing frequency harmonics to remove.

Returns

  • na4 (float) – A metric to not only detect the onset of damage, but also to continue to react to the damage as it increases.

  • cur_info (tuple of (int, float)) – The information for the ‘current time record number’ in run ensemble. The first element of cur_info is the ‘current time record number’(M). The second element of cur_info is the average of each 2th central moment of M residual signals.

References

1

Zakrajsek, James & Handschuh, Robert & Decker, Harry. (1994). Application of fault detection techniques to spiral bevel gear fatigue data. Available from: https://ntrs.nasa.gov/citations/19940020010

Examples

>>> rpm = 180                                    # Revolution per minute
>>> fs = 50e3                                    # Sampling rate
>>> t = np.arange(0, (1 / 3) - 1 / fs, 1 / fs)   # Sample times
>>> freq_list = (51, 153)                        # Gear mesh frequencies
>>> f = (rpm/60,) + freq_list                    # Frequencies of signals
>>> prev_info = (0, 0)         # The information for the 'previous time record number' in run ensemble.
>>> n_harmonics = 2
>>> na4_list = []

# Assume that the gear condition is getting worse.

>>> for k in range(1, 11):
        # Motor shaft rotation and harmonic
        shaft_signal = np.sin(2 * np.pi * f[0] * t) + np.sin(2 * np.pi * 2 * f[0] * t)
        # Gear mesh vibration and harmonic for a pair of gears
        gm1_signal = 3 * np.sin(2 * np.pi * f[1] * t) + 3 * np.sin(2 * np.pi * 2 * f[1] * t)
        # Gear mesh vibration and harmonic for a pair of gears
        gm2_signal = 4 * np.sin(2 * np.pi * f[2] * t) + 4 * np.sin(2 * np.pi * 2 * f[2] * t)
        # Fault component signal
        fault_signal = 2 * (k / 6) * np.sin(2 * np.pi * 10 * f[0] * t)
        # New signal is the sum of gm1_signal, gm2_signal, and fault_signal.
        new_signal = shaft_signal + gm1_signal + gm2_signal + fault_signal

# Calculate NA4 na4_, cur_info = na4(new_signal, prev_info, fs, rpm, freq_list, n_harmonics) prev_info = cur_info na4_list.append(na4_)

>>> print(na4_list)
[1.536982703280907, 3.857738227803903, 5.590250485891509, 6.835250547872656, 7.755227746173137,
 8.457654233606695, 9.009683995782796, 9.454160950683573, 9.819352835339927, 10.12454304712786]

onebone.feature.snr

onebone.feature.snr.snr(x: ndarray, fs: Union[int, float] = 1000, nperseg: int = 256, noverlap: int = 32) ndarray

Extract the SNR(Signal-to-Noise-Ratio) feature from the signal using the ‘STFT’. SNR is the ratio between max power intensity of frequency and power of other frequencies at time t in the STFT spectrum.

\[P_{signal}(t) = max(|STFT(t,f)|)\]
\[SNR(t) = {P_{signal}(t) \over {\sum_{f}|STFT(t,f)|} - P_{signal}(t)}\]
Parameters
  • x (numpy.ndarray) – 1d-signal data. Must be real.

  • fs (int or float) – Sampling rate.

  • nperseg (int, default=256) – Length of each segment.

  • noverlap (int, default=32) – Number of points to overlap between segments.

Returns

snr (numpy.ndarray) – SNR of the x, 1d-array.

Examples

>>> fs = 1000.0
>>> t = np.linspace(0, 1, int(fs))
>>> x = 10.0 * np.sin(2 * np.pi * 20.0 * t)
>>> snr_array = snr_feature(x, fs)

Notes

  1. Get a snr array by using snr_feature for one of given signals.

  2. Make the segments of snr array and get the mean of each segment.

  3. Compare the mean of SNR between normal states and fault states. e.g. SNR_fault = np.mean(SNR_fault_array), SNR_normal = np.mean(SNR_normal_array)

  4. Typically, SNR_fault is smaller than SNR_normal.

onebone.feature.tacho

Convert tacho to angle or RPM.

onebone.feature.tacho.tacho_to_angle(x: ndarray, fs: Union[int, float], state_levels_trh: Union[int, float], indices_trh: int = 2, pulses_per_rev: int = 1, output_fs: Optional[Union[int, float]] = None, fit_type: str = 'linear') Tuple[ndarray, ndarray, ndarray]

Extract angle signal from tachometer pulses.

Parameters
  • x (numpy.ndarray) – Tachometer pulse signal(1-D).

  • fs (int or float) – Sample rate.

  • state_levels_trh (int or float) – The difference between state levels used to identify pulses. (The state levels used to identify pulses.)

  • indices_trh (int, default=2) – The difference between indices of the first samples of high-level-state of pulses.

  • pulses_per_rev (int, default=1) – Number of tachometer pulses per revolution.

  • output_fs (int or float, default=None) – Output sample rate. When the default is None, the output_fs is the fs.

  • fit_type (str, default="linear") – Fitting method

Returns

  • angle (numpy.ndarray) – Rotational angle(1-D).

  • t (numpy.ndarray) – Time(1-D) expressed in seconds.

  • tp (numpy.ndarray) – Pulse locations(1-D) expressed in seconds.

Examples

>>> x = np.array([0,1,0,1,0,0,1,0,0,1])
>>> fs = 10
>>> state_levels_trh = 0.5
>>> angle, t, tp = tacho_to_angle(x, fs, state_levels_trh)
>>> angle
array([-6.28318531e+00, -4.18879020e+00, -2.09439510e+00,  1.16262283e-15,
       2.09439510e+00,  4.18879020e+00,  6.28318531e+00,  8.37758041e+00,
       1.04719755e+01,  1.25663706e+01])
>>> t
array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])
>>> tp
array([0.3, 0.6, 0.9])
onebone.feature.tacho.tacho_to_rpm(x: ndarray, fs: Union[int, float], state_levels_trh: Union[int, float], indices_trh: int = 2, pulses_per_rev: int = 1, output_fs: Optional[Union[int, float]] = None, fit_type: str = 'linear') Tuple[ndarray, ndarray, ndarray]

Extract RPM signal from tachometer pulses.

Parameters
  • x (numpy.ndarray) – Tachometer pulse signal(1-D).

  • fs (int or float) – Sample rate.

  • state_levels_trh (int or float) – The difference between state levels used to identify pulses. (The state levels used to identify pulses.)

  • indices_trh (int, default=2) – The difference between indices of the first samples of high-level-state of pulses.

  • pulses_per_rev (int, default=1) – Number of tachometer pulses per revolution.

  • output_fs (int or float, default=None) – Output sample rate. When the default is None, the output_fs is the fs.

  • fit_type (str, default="linear") – Fitting method.

Returns

  • rpm (numpy.ndarray) – Rotational speed(1-D).

  • t (numpy.ndarray) – Time(1-D) expressed in seconds.

  • tp (numpy.ndarray) – Pulse locations(1-D) expressed in seconds.

Examples

>>> x = np.array([0,1,0,1,0,0,1,0,0,1])
>>> fs = 10
>>> state_levels_trh = 0.5
>>> rpm, t, tp = tacho_to_rpm(x, fs, state_levels_trh)
>>> rpm
array([200., 200., 200., 200., 200., 200., 200., 200., 200., 200.])
>>> t
array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])
>>> tp
array([0.3, 0.6, 0.9])

onebone.feature.tacholess

Track and extract a instantaneous frequency(IF) profile from vibration signal

onebone.feature.tacholess.two_step_if(x: ndarray, fs: Union[int, float], f_start: Union[int, float], f_tol: Union[int, float], filter_bw: Union[int, float], window: Union[str, Tuple, ndarray] = 'hann', nperseg: int = 256, noverlap: Optional[int] = None, **kwargs) ndarray

Track and extract a instantaneous frequency(IF) profile from vibration signal, based on Two-step method.

Note

If you have a tachometer pulse signal, use tacho_to_rpm function.

two_step_if uses the local maxima technique \({}^{[1]}\) for IF estimation, as follows;

\[\begin{split}f_{max}(t) = \underset{f}{Argmax}{\left|{X(t,f)}\right|}^2, \quad\mathrm{for}\; f \in \mathit{\Delta}f_t \\ \\ \mathit{\Delta}f_t \subset \left\{f_{max}(t-d\tau)-\delta f, \; f_{max}(t-d\tau)+\delta f\right\}\end{split}\]

where, \({\delta f}\) is the given frequency tolerance for maxima detection, \(X(t,f)\) is the STFT of signal \(x(t)\) computed for frequency values in set \(\mathit{\Delta}f_t\), specified from the previous estimate \(f_{max}(t-d\tau)\). tau is time defined as a window position. Note that for t=0, \(\mathit{\Delta}f_t\) should be given by the user.

Parameters
  • x (numpy.ndarray of shape (length of x, )) – A vibration 1-D signal.

  • fs (int or float) – Sampling rate. [Hz]

  • f_start (int or float) – Starting frequency point for the IF estimation. [Hz]

  • f_tol (int or float) – Frequency tolerance for maxima detection. [Hz]

  • filter_bw (int or float) – frequency bandwidth for filtration. [Hz]

  • window (str or tuple or numpy.ndarray, default="hann") – Desired window to use for scipy.signal.stft. If window is a string or tuple, it is passed to get_window to generate the window values, which are DFT-even by default. See get_window for a list of windows and required parameters. If window is array_like it will be used directly as the window and its length must be nperseg. Defaults to a Hann window.

  • nperseg (int, default=256) – Length of each segment for scipy.signal.stft.

  • noverlap (int, default=None) – Number of points to overlap between segments. If None, noverlap = nperseg // 2. Defaults to None. When specified, the COLA constraint must be met; i.e. (x.shape[axis] - nperseg) % (nperseg-noverlap) == 0. For more information, see Notes of scipy.signal.stft.

  • **kwargs (dict) – Additional parameters for scipy.signal.stft.

Returns

inst_freq (numpy.ndarray of shape (x.size - 1,)) – A instantaneous frequency(IF) profile. For improved results try to manipulate f_tol and f_tol parameters. You might also change spectrogram options.

References

1

Jacek Urbanek, Tomasz Barszcz, Jerome Antoni. (2013). A two-step procedure for estimation of instantaneous rotational speed with large fluctuations. https://doi.org/10.1016/j.ymssp.2012.05.009.

Examples

>>> import numpy as np
>>> import matplotlib.pyplot as plt

Generate a test signal, sin wave whose frequency is modulated around 3kHz, corrupted by white noise.

>>> fs = 1e4
>>> n = 1e5
>>> time = np.arange(n) / fs
>>> mod = 500 * np.cos(2 * np.pi * 0.1 * time)
>>> carrier = 3 * np.sin(2 * np.pi * 3e3 * time + mod)
>>> x = carrier + np.random.rand(carrier.size) / 5  # test signal

Extract the instantaneous frequency from the signal.

>>> inst_freq = two_step_if(x, fs, f_start=3e3, f_tol=50, filter_bw=5,
window='hann', nperseg=4096, noverlap=3985)

Plot the instantaneous frequency(IF) profile.

>>> time = np.arange(x.size) / fs
>>> time = time[:-1]
>>> plt.plot(time, inst_freq)
>>> plt.title('Estimated the instantaneous frequency(IF) profile')
>>> plt.ylabel('Frequency [Hz]')
>>> plt.xlabel('Time [sec]')
>>> plt.show()

onebone.feature.time

Signal analysis for the time domain.

onebone.feature.time.crest_factor(x: ndarray, axis: Optional[int] = None) ndarray

Peak to average ratio along an axis.

\[crest factor = {|x_{peak}| \over {x_{rms}}}\]
Parameters
  • x (numpy.ndarray) – The data.

  • axis (None or int, default=None) – Axis along which to calculate crest factor. By default, flatten the array.

Returns

crest_factor (numpy.ndarray) – Peak to average ratio of x.

Examples

>>> x = np.array([[4, 9, 2, 10],
...               [6, 9, 7, 12]])
>>> crest_factor(x, axis=0)
array([0.39223219, 0.        , 0.97128567, 0.18107148])
>>> crest_factor(x, axis=1)
array([1.12855283, 0.68155412])
>>> crest_factor(x)
1.2512223376239555
onebone.feature.time.kurtosis(x: ndarray, axis: int = 0, fisher: bool = True, bias: bool = True) ndarray

Note

This method uses scipy.stats.kurtosis method as it is.

Compute the kurtosis (Fisher or Pearson) of a signal.

Parameters
  • x (numpy.ndarray) – The data.

  • axis (None or int, default=0) – Axis along which the kurtosis is calculated. If None, compute over the whole array a.

  • fisher (bool, default=True) – If True, Fisher’s definition is used (normal ==> 0.0). If False, Pearson’s definition is used (normal ==> 3.0).

  • bias (bool, default=True) –

  • False (If) –

  • bias. (then the calculations are corrected for statistical) –

Returns

kurtosis (numpy.ndarray) – The kurtosis of values along an axis. If all values are equal, return -3 for Fisher’s definition and 0 for Pearson’s definition.

Examples

>>> x = np.array([[4, 9, 2, 10],
...               [6, 9, 7, 12]])
>>> kurtosis(x)
array([-2., -3., -2., -2.])
onebone.feature.time.peak2peak(x, axis: Optional[int] = None) ndarray

Note

This method uses numpy.ptp method as it is.

Maximum to minimum difference along an axis.

Parameters
  • x (array_like) – The data.

  • axis (None or int, default=None) – Axis along which to find the peaks. By default, flatten the array.

Returns

p2p (numpy.ndarray) – The difference between the maximum and minimum values in x.

Examples

>>> x = np.array([[4, 9, 2, 10],
...               [6, 9, 7, 12]])
>>> ptp(x, axis=1)
array([8, 6])
>>> ptp(x, axis=0)
array([2, 0, 5, 2])
>>> ptp(x)
10
onebone.feature.time.rms(x: ndarray, axis: Optional[int] = None) ndarray

Root mean square along an axis.

Parameters
  • x (numpy.ndarray) – The data.

  • axis (None or int, default=None) – Axis along which to calculate rms. By default, flatten the array.

Returns

rms (numpy.ndarray) – Root mean square value of x.

Examples

>>> x = np.array([[4, 9, 2, 10],
...               [6, 9, 7, 12]])
>>> rms(x, axis=0)
array([ 5.09901951,  9.        ,  5.14781507, 11.04536102])
>>> rms(x, axis=1)
array([7.08872344, 8.80340843])
>>> rms(x)
7.99218368157289