python显示数组维度
时间: 2023-10-23 22:09:57 浏览: 34
要显示一个数组的维度,可以使用NumPy库的shape属性。例如:
```python
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr.shape)
```
输出:
```
(2, 3)
```
这表示数组arr有两行和三列。第一个数字是行数,第二个数字是列数。
相关问题
python 显示数组维度
要显示 Python 中数组(或者更准确地说是 Numpy 数组)的维度可以使用 `ndarray.shape` 属性。例如:
```python
import numpy as np
a = np.array([[1, 2], [3, 4], [5, 6]])
print(a.shape)
```
输出:
```
(3, 2)
```
这里 `a.shape` 返回的是一个元组,元组中的每个元素表示数组在该维度上的大小。上述示例中,数组 `a` 的第一维大小为 3,第二维大小为 2。
python显示二维数组的维度
要显示Python中二维数组的维度,可以使用numpy库中的shape属性。具体实现方法如下:
```python
import numpy as np
# 创建一个二维数组
arr = np.array([[1, 2, 3], [4, 5, 6]])
# 打印数组的维度
print(arr.shape)
```
输出结果为:
```
(2, 3)
```
其中,`(2, 3)`表示该二维数组有2行、3列。