qml.math.cast_like¶
- cast_like(tensor1, tensor2)[source]¶
Casts a tensor to the same dtype as another.
- Parameters
tensor1 (tensor_like) – tensor to cast
tensor2 (tensor_like) – tensor with corresponding dtype to cast to
- Returns
a tensor with the same shape and values as
tensor1
and the same dtype astensor2
- Return type
tensor_like
Example
>>> x = torch.tensor([1, 2]) >>> y = torch.tensor([3., 4.]) >>> cast_like(x, y) tensor([1., 2.])