Hi @ai_is_cool,
Surely this is an array with two columns, not one?
Not quite! In NumPy, x = np.array([200, 17])
creates a 1D array, which doesn’t have explicit rows or columns – just a single axis.
You can check its shape:
import numpy as np
x = np.array([200, 17])
print(x.shape) # Output: (2,)
Alternatively I can define x
as
x = np.array([200,
17])
print(x.shape) # Output: (2,)
Since the shape is (2,)
, it means the array has 2 elements along one axis, but no second axis (no explicit “rows” or “columns”).
If you want it to be explicitly a column vector (2 rows, 1 column), you’d reshape it:
x = np.array([200, 17]).reshape(2, 1) # Shape (2,1)
Or use:
x = np.array([[200], [17]]) # Also Shape (2,1)
If you want a row vector (1 row, 2 columns), you’d reshape it like this:
x = np.array([200, 17]).reshape(1, 2) # Shape (1,2)
Or:
x = np.array([[200, 17]]) # Also Shape (1,2)