在Python中,如果你想输出数组的维度,可以使用`numpy`库,它提供了`shape`属性和`ndim`属性来获取数组的维度信息。以下是使用`numpy`输出数组维度的步骤:
1. 导入`numpy`库。
```python
import numpy as np
2. 创建一个数组。
```python
a = np.array([[1, 2, 3], [4, 5, 6]])
3. 使用`shape`属性获取数组的维度。
```python
print(a.shape) 输出:(2, 3)
4. 使用`ndim`属性获取数组的维度数。
```python
print(a.ndim) 输出:2
`shape`属性返回一个元组,表示数组的每个维度的大小,而`ndim`属性返回一个整数,表示数组的维度数。