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: v = [ 1 2 3 ] v = \begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix} v = 1 2 3
Basis vectors in ℝ³: e 1 = [ 1 0 0 ] , e 2 = [ 0 1 0 ] , e 3 = [ 0 0 1 ] e_1 = \begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}, \quad e_2 = \begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix}, \quad e_3 = \begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix} e 1 = 1 0 0 , e 2 = 0 1 0 , e 3 = 0 0 1
2.3 Matrix (Shape: (m,n))
Shape: (2,3)
Example: A = [ 1 2 3 4 5 6 ] A = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix} A = [ 1 4 2 5 3 6 ]
Shape: (3,3)
2.4 3D Tensor (Shape: (l,m,n))
Shape: (2,2,3)
RGB Image Example (Shape: (height, width,3)):
Shape: (2,3,3)
3. Mathematical Operations with Shapes
3.1 Reshaping Operations
3.2 Shape Compatibility in Operations
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
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
Copy 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
Copy 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,)