简体   繁体   English

AttributeError: 模块 'scipy.stats' 没有属性 'signaltonoise'

[英]AttributeError: module 'scipy.stats' has no attribute 'signaltonoise'

I'm using scipy signaltonoise function below is the code but it returns an error.我正在使用下面的 scipy signaltonoise 函数是代码,但它返回一个错误。 I searched regarding this in github too but couldn't find it.我也在github中搜索过这个,但找不到。 Can you please help.你能帮忙吗。

import numpy as np
import cv2
import math
import os
import csv
from scipy import stats 
from PIL import Image
from skimage.color import rgb2gray
from multiprocessing import Pool
from skimage.feature import local_binary_pattern # Local Binary Pattern function
from scipy.stats import itemfreq # To calculate a normalized histogram
import scipy.stats as sp
from skimage.feature import hog
from scipy.ndimage.measurements import label
from scipy import signal as sg




def calc_snr(img):
    snr = stats.signaltonoise(img, axis=None)
    return snr


 snr = calc_snr(img)

scipy.stats.signaltonoise() was deprecated in scipy 0.16.0 and removed in 1.0.0. scipy.stats.signaltonoise() 在 scipy 0.16.0 中弃用并在 1.0.0 中被移除。 If you need to use the function without downgrading scipy, you can see the original code from the function before it was removed on github here , and reproduced below:如果您需要在不降级scipy的情况下使用该功能,您可以在此处查看github上删除之前该功能的原始代码,并复制如下:

import numpy as np
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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM