# I need help to convert the following eq to tensor

x is an image.
R = x[0,0,:,:]
G = x[0,1,:,:]
B = x[0,2,:,:]

v_p = torch.tensor([R, G, B, torch.pow(R,2), torch.pow(G,2), torch.pow(B,2), R * G, G * B, B * R, 1.0])

The problem is many of the elements have different dtype.

The following is the error,

ValueError Traceback (most recent call last)
in ()
----> 1 v_p = model.get_param(img)
2 v_p.shape

in get_param(x)
—> 67 v_p = torch.tensor([R, G, B, torch.pow(R,2), torch.pow(G,2), torch.pow(B,2), R * G, G * B, B * R, 1.0])
68 return v_p.reshape(1,10)
69

ValueError: only one element tensors can be converted to Python scalars

I don’t want to convert to numpy*

For different data types, you might need to store the tensors in a list, as I don’t think there is a workaround currently.
Numpy will convert the arrays in the same way PyTorch does:

``````tmp = np.array([np.zeros(1).astype(np.float32), np.zeros(1).astype(np.float64)])
print(tmp.dtype)
> float64
print(tmp[0].dtype)
> float64

tmp = torch.tensor([torch.randn(1), torch.randn(1).double()])
print(tmp.dtype)
> torch.float64
``````

The error might point instead to a shape mismatch.