错误:x 和 y 必须具有相同的第一维

问题描述

Error: raise ValueError(f"x and y must have the same first dimension,but " ValueError: x and y must have the same first dimension,but have shape (1,) and (606976,)

当我在 python 中运行 plot bursts 代码行时出现此错误:(此行的所有信息如下)

    plot_bursts((self.time_array),(self.data),(self.bursting),labels=['C4','Detected Burst'])

for i in range(len(self.data)):
            i += 1
            t = i/(2034.50521)
            self.time_array.append(t)


self.bursting = detect_bursts_dual_threshold(self.data,self.fs,self.amp_dual_thresh,self.f_range)




data_set = list(C4.items())
    C4 = np.array(data_set)
    C4 = C4[0][1]
    C4 = C4.flatten()
    np.array(C4)
    self.data = C4

不知道要修复什么,请帮忙谢谢!

解决方法

您的问题不清楚,但这表明您在准备要绘制的数据时犯了一个错误。

我假设您在幕后使用了 matplotlib。例如,当您将不同大小的向量传递给 plot 时,会出现此消息。

import matplotlib.pyplot as plt
plt.plot([1],[1,2])

绘图将尝试将 x 中的每个元素与 y 中的一个元素进行匹配,但会失败,因为两个输入中的元素数量不同。