【发布时间】:2018-04-27 12:01:04
【问题描述】:
我正在为 Python 代码而苦苦挣扎。我想这样做equation。
这是我的代码:
fs= 5000
T=np.linspace(0,2.2,fs)
n=np.arange(fs*2.2)
u=[]
for x in T:
if x < 0.2:
u.append(x * np.sin(34*np.pi*n/fs))
if (x >= 0.2 and x < 0.8):
u.append(1/x * np.log10(x+1))
if x >= 0.8 and x < 1.4:
u.append((x^2 + 1) * np.sin(12*np.pi*n/fs))
if x >= 1.4:
u.append(np.sin(20*np.pi*n/fs + x/3))
而python返回:
File "D:/Semestr V/Podstawy Transmisji Danych/labki-ZAD3.py", line 20, in <module>
u.append((x^2 + 1) * np.sin(12*np.pi*n/fs))
TypeError: unsupported operand type(s) for ^: 'numpy.float64' and 'int'
【问题讨论】:
-
毫无疑问,标题本身没有意义。
-
出于文体目的,为您的逻辑使用 if、elif、else 约定。
标签: python algorithm list numpy equation