Tensor Shape
1. Mathematical Definition
The shape of a tensor is an ordered tuple (n₁, n₂, ..., nₖ) where each nᵢ represents the size of the i-th dimension. It describes the number of elements along each dimension of the tensor.
2. Mathematical Examples by Dimensionality
2.1 Scalar (Shape: ())
Shape: ()
Example: 5
Components: Single value
2.2 Vector (Shape: (n))
Shape: (3)
Example:
Basis vectors in ℝ³:
2.3 Matrix (Shape: (m,n))
Shape: (2,3)
Example:
Shape: (3,3)
Identity Matrix:
2.4 3D Tensor (Shape: (l,m,n))
Shape: (2,2,3)
Example:
RGB Image Example (Shape: (height, width,3)):
Shape: (2,3,3)
3. Mathematical Operations with Shapes
3.1 Reshaping Operations
Original shape: (4,) → vector
Reshaped to (2,3) → matrix
Reshaped to (3,2) → matrix
3.2 Shape Compatibility in Operations
Matrix Multiplication ():
A shape:
B shape:
Result shape:
Example:
3.3 Broadcasting Rules
Vector + Scalar: Shape (3,) + () → (3,)
Matrix + Vector: Shape (2,3) + (3,) → (2,3)
4. Special Tensor Shapes in Mathematics
4.1 Square Matrices (n,n)
Shape: (2,2)
Shape: (3,3)
4.2 Diagonal Matrices
Shape: (3,3)
4.3 Symmetric Tensors
This shows a symmetric matrix where the entries satisfy .
Shape: (3,3)
5. Applications with Specific Shapes
5.1 Physics Examples
Stress Tensor (Shape: (3,3)):
Electromagnetic Field Tensor (Shape: (4,4)):
5.2 Linear Algebra Examples
yRotation Matrix (Shape: (3,3)):
[cos θ -sin θ 0]
[sin θ cos θ 0]
[0 0 1]
Projection Matrix (Shape: (n,n)):
P = A(AᵀA)⁻¹Aᵀ
5.3 Data Science Examples
Feature Matrix (Shape: (samples, features)):
Shape: (3,4)
[x₁₁ x₁₂ x₁₃ x₁₄]
[x₂₁ x₂₂ x₂₃ x₂₄]
[x₃₁ x₃₂ x₃₃ x₃₄]
Neural Network Layer (Shape: (batch_size, neurons)):
Shape: (2,3)
[n₁₁ n₁₂ n₁₃]
[n₂₁ n₂₂ n₂₃]
6. Shape Transformations
6.1 Transpose Operation
Original Shape: (2,3)
Transposed Shape: (3,2)
6.2 Flatten Operation
Original Shape: (2,2,2)
Flattened Shape: (8,)
Last updated