# Specified TensorFlow Data Type in Python

## Python TensorFlow Basic: Exercise-14 with Solution

Write a Python program that creates a TensorFlow tensor with a specified data type (e.g., float32) and prints its data type

**Sample Solution:**

**Python Code:**

```
import tensorflow as tf
# Declare the data type (e.g., float32)
data_type = tf.float32
# Create a TensorFlow tensor with the specified data type
# Tensors are multi-dimensional arrays with a uniform type (called a dtype ).
ts = tf.constant([1.0, 2.0, 3.0], dtype=data_type)
# Print the data type of the tensor
print("Data Type of the Tensor:", ts.dtype)
```

Output:

Data Type of the Tensor: <dtype: 'float32'>

**Explanation:**

In the exercise above -

- Import TensorFlow as tf.
- Define the desired data type, such as tf.float32, and store it in the data_type variable.
- Create a TensorFlow tensor using tf.constant() with the specified data type by providing the dtype argument.
- Finally, we print the data type of the created tensor using tensor.dtype.

**Python Code Editor:**

**Previous:** Common TensorFlow data types in Python.

**Next:** Convert TensorFlow Tensor data type in Python.

**What is the difficulty level of this exercise?**

**Weekly Trends**- 100 Python Projects for Beginners with solution
- Mastering NumPy: 100 Exercises with solutions
- SQL Tutorial
- SQL Inner Join
- Python Exercises, Practice, Solution
- Python Interview Questions and Answers: Comprehensive Guide
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript HTML Form Validation
- Java Collection Exercises