Hi!
I have a list of tensors
my_list = [tensor(0.8223, device='cuda:0'), tensor(1.8351, device='cuda:0'), tensor(1.4888, device='cuda:0'),]
and i want their mean. I tried torch.mean(my_list)
, but got this error
TypeError: mean(): argument 'input' (position 1) must be Tensor, not list
Then I tried this np.mean(my_list)
and got this error
in _mean ret = ret.dtype.type(ret / rcount)
AttributeError: 'torch.dtype' object has no attribute 'type'
This solution works for me. Is there a better way of doing this and not using detach()
first?
new_list = [x.cpu().detach().numpy() for x in my_list]
my_mean = np.mean(new_list)
Also, what to do If i want the returned value to be a tensor(my_mean, device='cuda:0')
.
I tried this torch.cuda.FloatTensor(my_mean)
but got this error
TypeError: new(): data must be a sequence (got numpy.float32)
Thank you.