tf.keras.ops.convert_to_tensor
Stay organized with collections
Save and categorize content based on your preferences.
Convert a NumPy array or Python array to a tensor.
tf.keras.ops.convert_to_tensor(
x, dtype=None, sparse=None, ragged=None
)
Native tensors for the current backend or left unchanged unless the dtype,
sparse or ragged arguments are set.
Args |
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.
|
Returns |
A backend tensor of the specified dtype and sparseness.
|
Example:
x = np.array([1, 2, 3])
y = keras.ops.convert_to_tensor(x)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2026-10-31 UTC.
[null,null,["Last updated 2026-10-31 UTC."],[],[]]