Convert a NumPy array to a tensor.
tf.keras.ops.convert_to_tensor(
x, dtype=None, sparse=None
)
| Args | |
|---|---|
x | A NumPy array. |
dtype | The target type. |
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. |
| Returns | |
|---|---|
A tensor of the specified dtype. |
x = np.array([1, 2, 3]) y = keras.ops.convert_to_tensor(x)
© 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/keras/ops/convert_to_tensor