首页 > 解决方案 > Spyder 编译器显示错误的输出

问题描述

所以我试图运行以下代码:

import numpy as np 
import numpy.linalg as la 
x = np.array ( [ [1, 0, 1], [0, 1, 1], [0, 0, 1], [1, 1, 1]] )
y = np.array ( [1, 1, 0, 0] )
# solve using normal equations:
x_transpose = np.transpose(x) #calculating transpose
x_transpose_dot_x = x_transpose.dot(x) # calculating dot product
temp_1 = la.inv(x_transpose_dot_x) #calculating inverse
temp_2 = x_transpose.dot(y)
theta = temp_1.dot(temp_2)
print(theta)

使用 spyder IDE 的输出:

[2.22044605e-16 1.11022302e-16 5.00000000e-01]

使用 collab 或 py IDE 的输出:

[0.00000000e+00 2.22044605e-16 5.00000000e-01]

为什么 spyder 会产生错误的输出?我喜欢使用 spyder !

标签: pythonnumpyspyder

解决方案


推荐阅读