I have a numpy array of tensor values, [tensor(1), …, tensor(n)].
how to convert it to numpy array: [1, …, n].
Thanks
Robert
I have a numpy array of tensor values, [tensor(1), …, tensor(n)].
how to convert it to numpy array: [1, …, n].
Thanks
Robert
torch.cat(list_of_tensors).numpy()
should work.
Let me know, if you get any errors.
Thanks, no, I got this error: TypeError: cat(): argument ‘tensors’ (position 1) must be tuple of Tensors, not numpy.ndarray
It seems you are already dealing with numpy arrays, not PyTorch tensors.
In that case you could try to use np.concatenate
.
Yes, the array is numpy, but contains tensor elements. I need to convert these tensor elements to none tensor values.
I fixed like this:
tensor_arr = [torch.tensor(1), …, torch.tensor(n)]
var = [e.item() for e in tesnsor_arr]