AttributeError:“ numpy.ndarray”对象没有属性“ find_peaks_cwt”进程

时间:2018-07-25 07:25:54

标签: python numpy scipy

import os
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import scipy
from scipy import signal

 def get_sig_from_txt(directory_path, filename):
    with open(directory_path + '\\' + filename) as f:
       content = f.readlines()
       content = [int(x.strip()) for x in content]
       return np.array(content)


for filename in dirr:
    signal = get_sig_from_txt(path, filename)
    idx_peak = signal.find_peaks_cwt(signal, np.arange(1, 16))

我收到错误:AttributeError:'numpy.ndarray'对象没有属性'find_peaks_cwt'进程。我该怎么办?

1 个答案:

答案 0 :(得分:0)

您已经隐藏了signal变量,该变量引用了scipy.signal模块。

只需将函数调用的结果分配给另一个名称:

for filename in dirr:
    sig = get_sig_from_txt(path, filename)
    idx_peak = signal.find_peaks_cwt(sig, np.arange(1, 16))