Answers for "an't convert np.ndarray of type numpy.object_. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool."

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 "an't convert np.ndarray of type numpy.object_. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool."

Python Answers by Framework

Browse Popular Code Answers by Language