Numpy Error: can't convert np.ndarray of type numpy.object_
Not sure why I'm getting this error when I'm doing:
batched_outputs = []
batched_outputs.append(output_sliced)
batched_outputs = torch.from_numpy(np.asarray(batched_outputs))
Where output_sliced
is a numpy
array.
1 answer

Code seems to be working fine. Perhaps problem with your
output_sliced
?import numpy as np import torch batched_outputs = [] output_sliced = np.random.random((2,3)) batched_outputs.append(output_sliced) batched_outputs = torch.from_numpy(np.asarray(batched_outputs))
I don't get any errors with the code above.
I don't know if you intended this, but do keep in mind that:
batched_outputs = [] output_sliced = np.random.random((2,3)) batched_outputs.append(output_sliced) print(np.asarray(batched_outputs).shape)
gives you
(1, 2, 3)