2016-07-08 2 views
0

내 코드를 사용 periodogram를 계산하기 위해 노력하고형식 오류 : ufunc '곱하기'서명 일치 유형 DTYPE ('S64') DTYPE ('S64') DTYPE와 루프를 포함하지 않았다 ('S64')

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') 

왜있어? 우분투 16.04, Python 2.7.11입니다.

+0

가능한 [TypeError : ufunc 'add'에 중복 서명이있는 유형이 루프에 포함되지 않았습니다.] (http://stackoverflow.com/questions/35013726/typeerror-ufunc-add-did-not-contain-a- 루프와 서명 일치 유형) –

답변

0

this question 에서처럼 모호한 오류 코드는 부동 소수점 데이터가 아닌 문자열 데이터에서 numpy 함수를 실행하면 발생합니다. rstripreturns a string으로 전화하십시오. 데이터 파일의 모양을 모르지만 x = np.array(x) 이후에 x = x.astype(np.float)을 추가하면 문제를 해결할 수 있습니다.

관련 문제