I’m compiling the exact same code in PyCharm and in CMD, but they’re giving me two different outputs:
PyCharm output – [np.float64(1.6000000000000003), -1]
CMD output – [1.6000000000000003, -1]
I was expecting the same output as CMD gives me in PyCharm, but it gives me “np.float64”.
import numpy as np
x_train = np.array([[10, 50], [20, 30], [25, 30], [20, 60], [15, 70], [40, 40], [30, 45], [20, 45], [40, 30], [7, 35]])
y_train = np.array([-1, 1, 1, -1, -1, 1, 1, -1, 1, -1])
n_train = len(x_train)
w = [0, -1]
a = lambda x: np.sign(x[0]*w[0] + x[1]*w[1])
N = 50
L = 0.1
e = 0.1
last_error_index = -1
for n in range(N):
for i in range(n_train):
if y_train[i]*a(x_train[i]) < 0:
w[0] = w[0] + L * y_train[i]
last_error_index = i
Q = sum([1 for i in range(n_train) if y_train[i]*a(x_train[i]) < 0])
if Q == 0:
break
if last_error_index > -1:
w[0] = w[0] + e * y_train[last_error_index]
print(w)
I tried reinstalling numpy in PyCharm but it didn’t help.
I guess it’s PyCharm issue, because in CMD and online compiler i have the same expected output.
New contributor
Ivan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.