elephant.signal_processing.zscore¶

elephant.signal_processing.
zscore
(signal, inplace=True)[source]¶ Apply a zscore operation to one or several neo.AnalogSignal objects.
The zscore operation subtracts the mean of the signal, and divides by its standard deviation :
If a neo.AnalogSignal object containing multiple signals is provided, the ztransform is always calculated for each signal individually.
If a list of neo.AnalogSignal objects is supplied, the mean and standard deviation are calculated across all objects of the list. Thus, all list elements are ztransformed by the same values of and . For a neo.AnalogSignal that contains multiple signals, each signal of the array is treated separately across list elements. Therefore, the number of signals must be identical for each neo.AnalogSignal object of the list.
Parameters:  signalneo.AnalogSignal or list of neo.AnalogSignal
Signals for which to calculate the zscore.
 inplacebool, optional
If True, the contents of the input signal is replaced by the ztransformed signal, if possible, i.e when the signal type is float. If the signal type is not float, an error is raised. If False, a copy of the original signal is returned. Default: True
Returns:  signal_ztransformedneo.AnalogSignal or list of neo.AnalogSignal
The output format matches the input format: for each input neo.AnalogSignal, a corresponding neo.AnalogSignal is returned, containing the ztransformed signal with dimensionless unit.
Raises:  ValueError
If inplace is True and the type of signal is not float.
Notes
You may supply a list of neo.AnalogSignal objects, where each object in the list contains the data of one trial of the experiment, and each signal of the neo.AnalogSignal corresponds to the recordings from one specific electrode in a particular trial. In this scenario, you will ztransform the signal of each electrode separately, but transform all trials of a given electrode in the same way.
Examples
Ztransform a single neo.AnalogSignal, containing only a single signal.
>>> import neo >>> import numpy as np >>> import quantities as pq >>> from elephant.signal_processing import zscore ... >>> a = neo.AnalogSignal( ... np.array([1, 2, 3, 4, 5, 6]).reshape(1,1) * pq.mV, ... t_start=0*pq.s, sampling_rate=1000*pq.Hz) >>> zscore(a).as_quantity() [[1.46385011] [0.87831007] [0.29277002] [ 0.29277002] [ 0.87831007] [ 1.46385011]] dimensionless
Ztransform a single neo.AnalogSignal containing multiple signals.
>>> b = neo.AnalogSignal( ... np.transpose([[1, 2, 3, 4, 5, 6], ... [11, 12, 13, 14, 15, 16]]) * pq.mV, ... t_start=0*pq.s, sampling_rate=1000*pq.Hz) >>> zscore(b).as_quantity() [[1.46385011 1.46385011] [0.87831007 0.87831007] [0.29277002 0.29277002] [ 0.29277002 0.29277002] [ 0.87831007 0.87831007] [ 1.46385011 1.46385011]] dimensionless
Ztransform a list of neo.AnalogSignal, each one containing more than one signal:
>>> c = neo.AnalogSignal( ... np.transpose([[21, 22, 23, 24, 25, 26], ... [31, 32, 33, 34, 35, 36]]) * pq.mV, ... t_start=0*pq.s, sampling_rate=1000*pq.Hz) >>> zscore([b, c]) [<AnalogSignal(array([[1.11669108, 1.08361877], [1.0672076 , 1.04878252], [1.01772411, 1.01394628], [0.96824063, 0.97911003], [0.91875714, 0.94427378], [0.86927366, 0.90943753]]) * dimensionless, [0.0 s, 0.006 s], sampling rate: 1000.0 Hz)>, <AnalogSignal(array([[ 0.78170952, 0.84779261], [ 0.86621866, 0.90728682], [ 0.9507278 , 0.96678104], [ 1.03523694, 1.02627526], [ 1.11974608, 1.08576948], [ 1.20425521, 1.1452637 ]]) * dimensionless, [0.0 s, 0.006 s], sampling rate: 1000.0 Hz)>]