Python - tensorflow.convert_to_tensor() Last Updated : 06 Mar, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks. convert_to_tensor() is used to convert the given value to a Tensor Syntax: tensorflow.convert_to_tensor( value, dtype, dtype_hint, name ) Parameters: value: It is the value that needed to be converted to Tensor.dtype(optional): It defines the type of the output Tensor.dtype_hint(optional): It is used when dtype is None. In some cases, a caller may not have a dtype in mind when converting to a tensor, so dtype_hint can be used as a soft preference. If the conversion to dtype_hint is not possible, this argument has no effect.name(optional): It defines the name for the operation. Returns: It returns a Tensor. Example 1: From Python list Python3 # Importing the library import tensorflow as tf # Initializing the input l = [1, 2, 3, 4] # Printing the input print('l: ', l) # Calculating result x = tf.convert_to_tensor(l) # Printing the result print('x: ', x) Output: l: [1, 2, 3, 4] x: tf.Tensor([1 2 3 4], shape=(4, ), dtype=int32) Example 2: From Python tuple Python3 # Importing the library import tensorflow as tf # Initializing the input l = (1, 2, 3, 4) # Printing the input print('l: ', l) # Calculating result x = tf.convert_to_tensor(l, dtype = tf.float64) # Printing the result print('x: ', x) Output: l: (1, 2, 3, 4) x: tf.Tensor([1. 2. 3. 4.], shape=(4, ), dtype=float64) Comment More infoAdvertise with us Next Article Python - tensorflow.eye() A aman neekhara Follow Improve Article Tags : Python Python-Tensorflow Practice Tags : python Similar Reads TensorFlow - How to create one hot tensor TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. One hot tensor is a Tensor in which all the values at indices where i =j and i!=j is same. Method Used: one_hot: This method accepts a Tensor of indices, a scalar defin 2 min read Introduction to Tensor with Tensorflow Tensor is a multi-dimensional array used to store data in machine learning and deep learning frameworks, such as TensorFlow. Tensors are the fundamental data structure in TensorFlow, and they represent the flow of data through a computation graph. Tensors generalize scalars, vectors, and matrices to 5 min read How To Convert Numpy Array To Tensor We are given a NumPy array, and our task is to convert it into a TensorFlow tensor. This is useful when integrating NumPy-based data with TensorFlow pipelines, which support acceleration using GPU and TPU. For example, converting [[1, 2], [3, 4]] results in a TensorFlow object that looks like: Pytho 2 min read Python - tensorflow.gather() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. gather() is used to slice the input tensor based on the indices provided. Syntax: tensorflow.gather( params, indices, validate_indices, axis, batch_dims, name) Paramete 2 min read Python - tensorflow.eye() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. tensorflow.eye() is used to generate identity matrix. Syntax: tensorflow.eye( num_rows, num_columns, batch_shape, dtype, name) Parameters: num_rows: It is int32 scalar 2 min read Python - tensorflow.raw_ops.Acosh() TensorFlow is open-source python library designed by Google to develop Machine Learning models and deep learning  neural networks. TensorFlow raw_ops provides low level access to all TensorFlow operations. Acosh() is used to find element wise inverse hyperbolic cosine of x. Syntax: tf.raw_ops.Acosh( 1 min read Like