qml.math.convert_like

convert_like(tensor1, tensor2)[source]

Convert a tensor to the same type as another.

Parameters
  • tensor1 (tensor_like) – tensor to convert

  • tensor2 (tensor_like) – tensor with corresponding type to convert to

Returns

a tensor with the same shape, values, and dtype as tensor1 and the same type as tensor2.

Return type

tensor_like

Example

>>> x = np.array([1, 2])
>>> y = tf.Variable([3, 4])
>>> convert_like(x, y)
<tf.Tensor: shape=(2,), dtype=int64, numpy=array([1, 2])>

Contents

Using PennyLane

Release news

Development

API

Internals