python - TypeError: (typecode 'l') 根据转换规则 ''same_kind'' 同时使用互相关
问题描述
我正在尝试使用互相关。我正在调查 x 和 y 之间的滞后是 1 个时间间隔。
我有这样的代码:
x= ([1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1])
y= ([0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1])
fig, [ax1, ax2] = plt.subplots(2, 1, sharex=True)
ax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, lw=2)
ax1.grid(True)
ax1.acorr(x, usevlines=True, normed=True, maxlags=50, lw=2)
ax1.grid(True)
ax2.acorr(y, usevlines=True, normed=True, maxlags=50, lw=2)
ax2.grid(True)
plt.show()
但是当我运行代码时,它给了我下图中给出的这个错误。我有点卡在这里。
有任何想法吗?
解决方案
您应该将输入转换为类型为 np.float 的 numpy 数组,如下所示:
x= np.array([1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1], dtype=np.float)
y= np.array([0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1], dtype=np.float)
另外您maxlags
的太大(请参阅上述修复后出现的下一个错误)
推荐阅读
- python - 用 HoughCircles 找不到欲望圈
- python - 无法同时使用 .openssh 密钥和密码通过 Paramiko 连接到 SFTP
- reactjs - 反应来自另一个组件的触发组件
- traffic - 蝗虫 - 从 RPS 方程中提取响应时间?
- html - 在 Django 中创建轮播滑块的问题
- c# - 使用 System.Drawing.Graphics 进行地图投影
- python - Airflow DAG 脚本在日志中打印值
- javascript - 包含重复值的数组
- sql - 如何在 sql server 中使用 select * 和 group by 子查询
- ios - 每个模式添加不同版本的框架