📅  最后修改于: 2023-12-03 15:29:28.190000             🧑  作者: Mango
arr.shape
In NumPy, arr.shape
is an attribute of a NumPy array that returns the dimensions of the array. It returns a tuple of integers, where each integer represents the length of the corresponding dimension of the array.
arr.shape
arr.shape
returns a tuple of integers, where each integer represents the length of the corresponding dimension of the array.
Consider the following example:
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print(arr.shape)
Output:
(3, 3)
Here, we have created a 3x3 NumPy array and printed its shape
attribute. This has returned the tuple (3, 3)
which tells us that the array has 2 dimensions, and the length of the first dimension is 3, while the length of the second dimension is also 3.
In this tutorial, we have introduced arr.shape
in NumPy and explained how it returns the dimensions of a NumPy array. By understanding this attribute, you can work with multi-dimensional arrays in NumPy and perform advanced operations in your programs.