为什么这个数组的值没有改变?

时间:2019-08-31 22:44:01

标签: python numpy

我正在尝试对机器学习算法进行矢量化处理,但是临时数组没有更改值。

我已经尝试用变量替换临时变量,它可以工作,但是我想看看为什么它不能用于数组。

def step_gradient(theta, x_values, y_values, learningRate):

    temp_theta = np.array([0, 0])
    error = ((x_values * theta[1]) + theta[0]) - y_values
    errorM = np.dot(error, x_values)
    error = sum(error) #error works

    #below is the problem
    #theta 1 - error... does = 0.75

    temp_theta[1] = theta[1] - ((errorM/len(x_values)) * learningRate)
    temp_theta[0] = theta[0] - ((error/len(x_values)) * learningRate)
    theta[1] = temp_theta[1]
    theta[0] = temp_theta[0]

    return theta

我希望temp_theta的值发生变化,但保持不变

1 个答案:

答案 0 :(得分:0)

我检查了

((error/len(x_values)) * learningRate) 

不等于零。由于某些原因,temp_theta[0]'s的值不会改变。

相关问题