首页 > 解决方案 > TypeError:尝试运行函数时无法解压不可迭代的 NoneType 对象

问题描述

我在代码的最后一行收到“TypeError: cannot unpack non-iterable NoneType object”的错误。你能帮我解决这个问题吗?

import matplotlib.pyplot as plt

#Weights (lb)
Measured = [158, 164.2, 160.3, 159.9, 162.1, 164.6,
169.6, 167.4, 166.4, 171, 171.2, 172.6]

#time step of 1 day
time_step = 1

#kalman Gain
Kg = 4/10

def predict_using_gain_guess(updated_estimate, gain_rate):
    estimates, predictions = [updated_estimate], []

    for z in Measured:
        #predict new position based on hypothesis that we are gaining 1lb every day
        prediction_hp = updated_estimate + gain_rate*time_step

        #update filter
        updated_estimate = prediction_hp + Kg * (z - prediction_hp)

        #save
        estimates.append(updated_estimate)
        predictions.append(prediction_hp)

initial_estimate = 160
estimates, predictions = predict_using_gain_guess(
    updated_estimate=initial_estimate, gain_rate=1)

标签: pythonpython-3.x

解决方案


推荐阅读