Tensor Dimensions
A tensor's rank indicates the number of axes it contains, and the size of each dimension represents the length along that axis.
0-D Tensor (Scalar)
This is a single number or a lone value.
import tensorflow as tf scalar = tf.constant(3.14) print(scalar)
1-D Tensor (Vector)
An array of numbers, similar to a list in Python.
vector = tf.constant([1, 2, 3]) print(vector)
2-D Tensor (Matrix)
A structured dataset made up of rows and columns.
matrix = tf.constant([[1, 2], [3, 4], [5, 6]]) print(matrix)
3-D and Higher-Dimensional Tensors
Used to represent more complex structures, such as images and video data.
tensor_3d = tf.constant([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) print(tensor_3d)
Properties of a Tensor
Tensors have several properties:
-
shape: A tuple representing the dimensions of the tensor. -
dtype: The data type stored in the tensor (e.g., float32, int32). -
device: Information about the device (CPU/GPU) where the tensor is executed.
example_tensor = tf.constant([[1, 2, 3], [4, 5, 6]], dtype=tf.float32) print(f"Shape: {example_tensor.shape}") # Shape: (2, 3) print(f"Data Type: {example_tensor.dtype}") # Data Type: <dtype: 'float32'>
By examining the properties of a tensor, you can easily determine its structure and data type.
In the next lesson, we'll go over a brief quiz to review what we have learned so far.
Lessons in this chapter · Machine Learning: Learning Patterns Hidden in Data
- 1. What’s All the Hype About? What Is Machine Learning?
- 2. What Are Neural Networks That Mimic the Human Brain?
- 3. How Perceptrons Work
- 4. Taking It Further: What Is Deep Learning?
- 5. Machine Learning vs. Deep Learning: Key Differences
- 6. Multiple Choice Quiz
- 7. What Does It Mean to Train AI?
- 8. The Result of AI Training: Files Made of Matrices
- 9. Supervised Learning: Learning with the Right Answers
- 10. Unsupervised Learning: Finding Patterns Without Answers
- 11. Reinforcement Learning: Learning Through Rewards
- 12. Fill-in-the-Blank Quiz
- 13. TensorFlow: A Library for Machine Learning and Deep Learning
- 14. Tensor: The Core Unit of TensorFlow
- 15. Tensor Dimensions
- 16. Multiple Choice Quiz
- 17. Understanding Tensor Operations
- 18. Top 5 Most Used TensorFlow APIs
- 19. Building a Simple Linear Regression Model with TensorFlow
- 20. Fill-in-the-Blank Quiz
- 21. Keras: A Simple and Intuitive Neural Network Library
- 22. Training and Evaluating Models with Keras
- 23. Multiple Choice Quiz
Questions about the Dimensionality of Tensors
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help