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.
- one_hot: This method accepts a Tensor of indices, a scalar defining depth of the one hot dimension and returns a one hot Tensor with default on value 1 and off value 0. These on and off values can be modified.
Indices: tf.Tensor([1 2 3], shape=(3, ), dtype=int32) Res: tf.Tensor( [[0. 1. 0.] [0. 0. 1.] [0. 0. 0.]], shape=(3, 3), dtype=float32)
Example 2: This example explicitly defines the on and off values for the one hot tensor.
Indices: tf.Tensor([1 2 3], shape=(3, ), dtype=int32) Res: tf.Tensor( [[-1 3 -1] [-1 -1 3] [-1 -1 -1]], shape=(3, 3), dtype=int32)
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- TensorFlow - How to create a tensor of all ones that has the same shape as the input tensor
- TensorFlow - How to create a tensor with all elements set to one
- TensorFlow - How to create a numpy ndarray from a tensor
- TensorFlow - How to stack a list of rank-R tensors into one rank-(R+1) tensor in parallel
- One Hot Encoding using Tensorflow
- Introduction to Tensor with Tensorflow
- TensorFlow - How to add padding to a tensor
- ML | One Hot Encoding of datasets in Python
- Matplotlib.pyplot.hot() in Python
- TensorFlow - How to create a TensorProto
- wxPython - Create Radio Button using Create() function
- wxPython - Create Static Box using Create() method
- Create and display a one-dimensional array-like object using Pandas in Python
- Python program to check if a string has at least one letter and one number
- Python | Classify Handwritten Digits with Tensorflow
- Introduction to TensorFlow
- Python | Tensorflow cos() method
- Linear Regression Using Tensorflow
- Python | Tensorflow nn.sigmoid()
- Python | Tensorflow nn.relu() and nn.leaky_relu()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.