【发布时间】:2015-01-10 00:18:44
【问题描述】:
您好,我希望得到一些帮助
import numpy as np
import math
import matplotlib.pylab as plt
import pandas as pd
from scipy.interpolate import interp1d
from scipy.signal import butter, filtfilt
from scipy import interpolate
Ic = 400
lower_Ig = 720 #the lower limit of the generator current Ig
Upper_Ig = 1040 #Upper limit
Ix=range(-60,61,1)
for j in range(40, 80, 10):
Var=(40000* j)/ 10000
#print Var
for c in range(lower_Ig, Upper_Ig+1, 40):
#print c
Names =['Vg','V3', 'V4']
Data = pd.read_csv('/Documents/JTL_'+str(Var)+'/Ig='+str(c)+'/Grey_Zone.csv', names=Names)
Vg = Data['Vg']
V3 = Data['V3']
V4 = Data ['V4']
Prf = V4 / Vg
#print Prf
C = 0.802
freq = 100
b, a = butter(2, (5/C)/(freq/2), btype = 'low')
yg = filtfilt(b, a, Vg) # filter with phase shift correction
y4 = filtfilt(b, a, V4) # filter with phase shift correction
SW = y4 / yg
if SW == np.nan: #I need a condition here that if -inf is encountered then the programme should loop to next c value in for loop
continue
f = interp1d( SW, Ix )
print f(0.25), f(0.5), f(0.75)
print f(0.75)-f(0.25)
我尝试使用不同的 numpy 函数,但总是遇到同样的错误
The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
我认为我不能使用any() 或all(),因为这将只包含所有数据,我想忽略-inf。非常感谢任何帮助
【问题讨论】:
-
哪一行给出了这个错误?
-
@rpattiso
if SW == np.nan导致错误 -
为什么使用
any或all会包含所有数据?它会将它们包含在什么中? -
@rpattiso 根据我对文档
all的理解返回整个数组,而不评估数组中的任何内容,并且不区分 -inf 或值,除非我有没有完全想明白?我想要的是检查任何 NaN 值,一旦遇到 NaN 值,文件将被忽略,循环继续进行下一次迭代,即下一个文件。
标签: python if-statement for-loop numpy continue