1. 使用列表推导式:
```python
rows = 3
cols = 4
array = [[None for _ in range(cols)] for _ in range(rows)]
print(array)
输出:
```
[[None, None, None, None], [None, None, None, None], [None, None, None, None]]
2. 使用嵌套循环:
```python
rows = 3
cols = 4
array = []
for i in range(rows):
row = []
for j in range(cols):
row.append(None)
array.append(row)
print(array)
输出:
```
[[None, None, None, None], [None, None, None, None], [None, None, None, None]]
3. 使用NumPy库:
```python
import numpy as np
rows = 3
cols = 4
array = np.zeros((rows, cols))
print(array)
输出:
```
[[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]]
你可以根据需要调整数组的大小和初始化的值。如果需要创建一个全为0的二维数组,可以使用`np.zeros`函数;如果需要创建一个全为1的二维数组,可以使用`np.ones`函数;如果需要创建一个指定元素填充的二维数组,可以使用`np.full`函数。
请告诉我,