Index out of range error

Hi I’m getting this index out of range error when plotting the results of a 2 layer neural network.

The input is a CSV file with (x,y) coordinates and a y-output for whether that point is deemed correct or not according to some rule.

Could I have some help in understanding the error?

plt.pcolormesh(xrange,yrange,(hid.cpu()[:,node]).view(yrange.size()[0],xrange.size()[0]), cmap='Wistia', shading='auto')
IndexError: index 1 is out of bounds for dimension 1 with size 1

PyTorch code

class Full3Net(torch.nn.Module):
    def __init__(self, hid):
        super(Full3Net, self).__init__()
        self.in_hid = torch.nn.Linear(2,hid)
        self.hid_out = torch.nn.Linear(hid,1)

    def forward(self, input):
        output1 = self.in_hid(input)
        self.hid1 = torch.tanh(output1)
        output2 = self.hid_out(self.hid1)
        self.hid2 = torch.tanh(output2)
        output = torch.sigmoid(self.hid2)
        return output

Can you supply a bit more of the code? It looks like the error is due to the fact that your network output is 1-dimensional (number of out-features of self.hid_out is 1) so if you try to index it at position node=1 you’re going to get an out-of-bounds error.

What shape would you like your output to have instead? Perhaps you want to use a Conv2d layer rather than a Linear one, if the dimensionality of your inputs is 2d (x, y) spatial coordinates.