Python->TypeError:^不支持的操作数类型 [英] Python -> TypeError: unsupported operand type(s) for ^

查看:80
本文介绍了Python->TypeError:^不支持的操作数类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力处理Python代码.我想这样做方程.

I am struggling with Python code. I want to do this 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返回:

And python returns:

  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'

推荐答案

幂运算符是 ** ^ 是按位XOR.

The power operator is **, ^ is bitwise XOR.

这篇关于Python->TypeError:^不支持的操作数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆