How to convert numpy.ndarray with data type np.complex128 to a torch tensor?

I have a variable named feature_data is of type numpy.ndarray, with every element in it being a complex number of form x + yi. How do I convert this to Torch tensor?

When I use the following syntax: torch.from_numpy(feature_data), it gives me an error saying
can’t convert np.ndarray of type numpy.complex128. The only supported types are: float64, float32, float16, int64, int32, int16, int8, uint8, and bool.

I want my torch tensor to have complex numbers in it after conversion from numpy.ndarray.

Try this: torch.Tensor(np.array([ ]), dtype=torch.cfloat)

1 Like