Array Shapes, Axes, and Broadcasting
To understand how NumPy arrays work in operations, you need to know about shapes and axes.
Shape
Every array has a .shape
, which shows how many elements it has in each dimension.
For example, an array with 2 rows and 3 columns has a shape of (2, 3)
.
Axes
An axis is a direction along which an operation is applied.
axis=0
: down the rows (vertical)axis=1
: across the columns (horizontal)
You will use axes with functions like sum()
, mean()
, and others.
Quiz
0 / 1
What does the shape
attribute represent in NumPy?
In NumPy, the `shape` attribute shows the of an array.
data type
dimensions
values
memory size
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help