What does this mean in numpy coding, (4,)
? You have an array and you run the shape of it and it gives you this answer. What does it mean?
x = np.array([1, 2, 3, 4])
x.shape
(4,)
What does this mean in numpy coding, (4,)
? You have an array and you run the shape of it and it gives you this answer. What does it mean?
x = np.array([1, 2, 3, 4])
x.shape
(4,)
Numpy's .shape
property is a tuple
that contains the size of the numpy object in every dimension.
Since your object is one-dimensional (a regular array), the length of the tuple is 1. Since your one-dimensional object contains 4 objects, it's size in the first dimension is 4, so the first element in the tuple is 4.
If the notation is confusing, tuple([4]) == (4,)
. The trailing comma is necessary because (4)
would simply be regular parenthesis around an expression.
If your numpy object was a two-dimensional array of size 3x4, the .shape
would give (3, 4)
.