Sets, ℝ and shapes: what W ∈ ℝ^(m×n) tells you
∈ means “is a member of”, ℝ is the real numbers, and ℝ with a raised size is the fastest way a paper tells you a tensor's shape.
1. The idea
A set is a collection of things, written with curly braces: {1, 2, 3}. The symbol ∈ means “is a member of”: 2 ∈ {1, 2, 3}, and 7 ∉ {1, 2, 3}. Small sets like these are rare in machine learning papers. What you'll see all the time is ∈ used to say what kind of thing a variable is.
ℝ is the set of all real numbers. ℝⁿ is the set of lists of n real numbers, and ℝ^(m×n) is the set of tables with m rows and n columns. So W ∈ ℝ^(768×3072) is the paper telling you W's shape: 768 rows, 3072 columns. In NumPy that is W.shape == (768, 3072). Whenever you meet a new symbol in a paper, look for the line that says which ℝ it lives in.
Set-builder notation describes a set by a rule: {x ∈ ℝ | x > 0} is “every real number x such that x is positive”. The bar reads “such that”. In Python it is a list comprehension: [x for x in xs if x > 0].
2. Try it: read a shape
Choose a matrix or a vector and set its size. The grid shows one square per number, with the maths and the NumPy shape underneath.
3. The math
4. The code (python)
import numpy as np
W = np.zeros((768, 3072)) # W in R^(768x3072)
print(W.shape, W.size) # (768, 3072) 2359296
x = np.array([0.5, -1.0, 2.0]) # x in R^3
print(x.shape) # (3,)
xs = [-2.0, 0.5, 3.0, -0.1]
print([v for v in xs if v > 0]) # [0.5, 3.0]
images = np.zeros((32, 3, 64, 64)) # a batch: B x C x H x W
print(images.ndim, images.shape) # 4 (32, 3, 64, 64)5. You’ll see this in
- Core Course chapter 6: arrays and batches shapes in practice
- Core Course chapter 16: convolutions batches of images, B × C × H × W
- Reference notes: linear algebra vector spaces, once you're comfortable with ℝⁿ
6. Check yourself
Finished this chapter?
What changed in ML architectures this week
New models worth knowing, benchmark moves, and one architecture explained in plain words. Free, once a week, unsubscribe anytime.