且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

类型错误:在尝试以指数方式拟合数据时,只能将长度为 1 的数组转换为 Python 标量

更新时间:2022-01-03 18:28:45

非 numpy 函数,如 math.abs()math.log10() 不与 numpy 数组一起玩得很好.只需将引发错误的行替换为:

Non-numpy functions like math.abs() or math.log10() don't play nicely with numpy arrays. Just replace the line raising an error with:

m = np.log10(np.abs(x))

除此之外,np.polyfit() 调用将不起作用,因为它缺少一个参数(并且您没有分配结果以供进一步使用).

Apart from that the np.polyfit() call will not work because it is missing a parameter (and you are not assigning the result for further use anyway).