Hi wsy!



 wsy:

This is my whole code. I checked that when the code<plt.plot(X_grid.detach().numpy,y_hat.detach().numpy,‘r’)> is commented out, there will be no error.But I can’t find the syntax error of this code.


Before you said that your error occurred in:
X_grid = torch.from_numpy(np.linspace(0,1,50)).float().view(-1, d)

But now you are saying it occurs in
plt.plot(X_grid.detach().numpy,y_hat.detach().numpy,‘r’)

Here, you are passing a function, numpy, to plt.plot(), rather than
the numerical values obtained by calling that function, numpy().
This line should be:
plt.plot(X_grid.detach().numpy(),y_hat.detach().numpy(),‘r’)

Note the two numpy() (rather than numpy).
As an aside, if this is indeed your entire code, d is not defined
anywhere.  But, given that, I would have expected you to get a
“d not defined” error first at this line:
nn.Linear(d,n_hidden_1)

Best.
K. Frank