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.
Questions about the Dimensionality of Tensors
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help