The shape of a NumPy array refers to the number of elements along each of its dimensions. In simpler terms, it specifies how many rows and columns a two-dimensional array has, or how many rows, columns, and depth a three-dimensional array has, and so on.
For example, consider a 2D array representing a table of values:
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
This array has 3 rows (each containing 3 elements) and 3 columns, and its shape is therefore (3, 3)
.
Understanding array shapes is crucial in NumPy operations, as many functions and operations work on arrays of specific shapes.
How to find shape of the array in Python?
To find the shape of the array, we use "shape" along with array name. In the above example, the array shape is 2x4, that means 2 rows and 4 columns.
We can also create an array with required dimensions as follows using "ndmin" as follows
As you can see, in the above output, the 5 dimension are displayed in [ ] brackets and also the shapes are displayed.
0 comments :
Post a Comment
Note: only a member of this blog may post a comment.