tf.keras.ops.convert_to_tensor

Convert a NumPy array or Python array to a tensor.

Native tensors for the current backend or left unchanged unless the dtype, sparse or ragged arguments are set.

x A NumPy array, Python array (can be nested) or a backend tensor.
dtype The target type. If None, the type of x is used.
sparse Whether to keep sparse tensors. False will cause sparse tensors to be densified. The default value of None means that sparse tensors are kept only if the backend supports them.
ragged Whether to keep ragged tensors. False will cause ragged tensors to be densified. The default value of None means that ragged tensors are kept only if the backend supports them.

A backend tensor of the specified dtype and sparseness.

Example:

x = np.array([1, 2, 3])
y = keras.ops.convert_to_tensor(x)