Calculate Signal to Noise ratio in python scipy version 1.1

16,411

As indicated in scipy issue #609 on github, the signaltonoise function

[...] is not useful except for backwards compatibility. The reason is that there's a Matlab signal-to-noise function http://www.mathworks.com/help/signal/ref/snr.html which means something different. This is not good, because scipy clones the Matlab interface of other signal-related functions, and this incompatibility apparently has no offsetting benefit.

If you do need this function for backward compatibility, the short implementation can be found in the history of scipy repository as (reproduced here without the documentation comments, license):

def signaltonoise(a, axis=0, ddof=0):
    a = np.asanyarray(a)
    m = a.mean(axis)
    sd = a.std(axis=axis, ddof=ddof)
    return np.where(sd == 0, 0, m/sd)
Share:
16,411
Pranjal Sahu
Author by

Pranjal Sahu

Deep Learning, Medical Imaging and Computer Vision

Updated on June 12, 2022

Comments

  • Pranjal Sahu
    Pranjal Sahu almost 2 years

    I have looked around online and it seems that the signaltonoise ratio function inside the scipy.stats is deprecated and is not available in version 1.1. Is there any other equivalent method inside scipy package since I have not been able to find it online.

    And if not scipy then is there any other library recommended for such calculations ?