gpt4 book ai didi

python - 类型错误 : ufunc 'multiply' did not contain a loop with signature matching types dtype ('S64' ) dtype ('S64' ) dtype ('S64' )

转载 作者:太空宇宙 更新时间:2023-11-03 16:22:43 27 4
gpt4 key购买 nike

我正在尝试使用我的代码计算周期图

from scipy import signal
import numpy as np
import matplotlib.pyplot as plt

x = [line.rstrip('\n') for line in open('27000.dat')]
x = np.array(x)
fs=64

f, Pxx_den = signal.periodogram(x, fs)
plt.semilogy(f, Pxx_den)
plt.xlabel('frequency [Hz]')
plt.ylabel('PSD [V**2/Hz]')
plt.show()

但是我得到了

  File "m3.py", line 9, in <module>
f, Pxx_den = signal.periodogram(x, fs)
File "/home/milenko/miniconda2/lib/python2.7/site-packages/scipy/signal/spectral.py", line 141, in periodogram
scaling, axis)
File "/home/milenko/miniconda2/lib/python2.7/site-packages/scipy/signal/spectral.py", line 273, in welch
return_onesided, scaling, axis)
File "/home/milenko/miniconda2/lib/python2.7/site-packages/scipy/signal/spectral.py", line 391, in csd
mode='psd')
File "/home/milenko/miniconda2/lib/python2.7/site-packages/scipy/signal/spectral.py", line 824, in _spectral_helper
scale = 1.0 / (fs * (win*win).sum())
TypeError: ufunc 'multiply' did not contain a loop with signature matching types dtype('S64') dtype('S64') dtype('S64')
为什么?我使用的是 Ubuntu 16.04,Python 2.7.11。

最佳答案

this question 所示,模糊的错误代码来自于对字符串数据而不是 float 据运行 numpy 函数。调用 rstrip returns a string 。我不知道您的数据文件是什么样的,但在 x = np.array(x) 之后添加 x = x.astype(np.float) 应该可以修复您的问题问题。

关于python - 类型错误 : ufunc 'multiply' did not contain a loop with signature matching types dtype ('S64' ) dtype ('S64' ) dtype ('S64' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38271932/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com