Machine learning

Hi everyone,

My question is why the outputs of these two codes are different? This is my code:


import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0,3,100)
def equation(x):
    return 3*x-1-np.square(x)
y = []
for number in x:
    y.append(equation(number)) 

plt.plot(x,y)

This is the answer code:


import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 3, 100)
y = -1*(x**2) + x*3 - 1
plt.plot(x,y) 

Hi @shhuseynli2018,

Your code is correct. It’s an issue of the answer-checking system which wants you to strictly follow the order of the formula given in this mission.

To prove it, just use once again your version of code, only that this time change the order in the return statement:

return -np.square(x)+3*x-1

Thank you very much!

1 Like