Answers for "can't convert np.ndarray of type numpy.object_"

1

can't convert np.ndarray of type numpy.object_.

import torch
import numpy as np

# Your test array without 'dtype=object'
a = np.array([
   np.array([-0.4287  , -1.193   , -2.156   , -0.2264  , -1.978   , -1.101   ,   -3.395   ,  0.2974  ], dtype=np.float16),
   np.array([-0.3386 ,  1.398  , -1.083  ,  0.2961 , -0.7354 , -1.326  , -4.33   ,  0.6284 ], dtype=np.float16)
])

print(a.dtype) # This should not be 'object'

b = torch.from_numpy(a)

print(b)
Posted by: Guest on October-27-2020

Code answers related to "can't convert np.ndarray of type numpy.object_"

Python Answers by Framework

Browse Popular Code Answers by Language