ValueError: ‘x‘ and ‘y‘ must have the same size

编程入门 行业动态 更新时间:2024-10-15 12:35:56

<a href=https://www.elefans.com/category/jswz/34/1753470.html style=ValueError: ‘x‘ and ‘y‘ must have the same size"/>

ValueError: ‘x‘ and ‘y‘ must have the same size

ValueError: ‘x’ and ‘y’ must have the same size

问题描述

出错代码

axes[0].errorbar(dates_of_observation, observed_lai, yerr=std_lai, fmt="o")


X是观测的日期,16天,而且数据也是对应的16个,为什么不对应呢?

原因

是一个画图的函数,该函数中,x和y不对应。源码是可以运行的,在我修改了变量之后,他的维度变化了,需要调整维度。
数量上对应还不够,有时数据结构,维度上也要对应(shape)
查看了原先observed_lai对应的维度,是个一维的列表,外面只有一个中括号

当我用dataframe读取数据之后,是个1*16的二维矩阵

解决方案

只需要将这两个中括号去掉就行了,也就是把1*16的二维度变成16的一维
在输入数据前添一行代码,使用np.reshape来调整形状

observed_lai = np.reshape(observed_lai,(16))

更多推荐

ValueError: ‘x‘ and ‘y‘ must have the same size

本文发布于:2023-11-15 04:40:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1593816.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ValueError   size

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!