'list' object has no attribute 'cat'

I want to concatenate two tensors, but I get the following error:

‘list’ object has no attribute ‘cat’

My code:

def forward(self, x):
        n, c, h, w = x.size()
        feat = x[0, :, 0, 0]
        this_img_conv = torch.zeros(c).cuda()
        this_img_conv = [Variable(this_img_conv)]
        this_img_conv = this_img_conv.cat(feat, 0)

I want to save the specific vector of x to the new tensor of this_img_conv. How can I achieve this function?

this_img_conv is a list, it should be a tensor so it have attribute ‘cat’

1 Like

As for the third line of your forward method,
which is this_img_conv = [Variable(this_img_conv)],
you should try this_img_conv = Variable(this_img_conv) without square brackets,
to make this_img_conv a Variable , not a list.

BTW, for concatenation, you can see torch.cat

1 Like

@Harry_Zhi This works well, thanks very much!