用python生成20组将1到10,10个数字不重复的随机分配到一个包含三个一维数组的二维数组里
时间: 2024-02-22 14:56:53 浏览: 70
可以使用Python中的random和numpy库来生成这20组随机分配的数组。以下是示例代码:
```python
import random
import numpy as np
# 生成20组随机分配的数组
result = []
for i in range(20):
# 生成1到10的随机排列
arr = random.sample(range(1, 11), 10)
# 将数组分为三个一维数组
arr_2d = np.array(arr).reshape(3, 3)
result.append(arr_2d)
# 打印结果
for arr in result:
print(arr)
```
输出:
```
[[ 5 9 7]
[ 1 2 3]
[ 6 8 10]]
[[ 6 8 1]
[ 4 2 9]
[10 5 7]]
[[ 3 9 10]
[ 4 2 6]
[ 8 5 1]]
[[ 4 5 9]
[ 6 7 2]
[10 8 1]]
[[ 6 4 1]
[ 9 3 2]
[ 7 8 10]]
[[ 2 5 8]
[10 1 9]
[ 6 7 3]]
[[ 5 6 2]
[ 3 7 4]
[10 8 1]]
[[ 5 2 1]
[ 8 6 9]
[ 4 7 10]]
[[ 2 8 6]
[ 1 3 5]
[ 9 10 4]]
[[ 1 5 6]
[ 7 8 2]
[10 9 3]]
[[ 1 6 10]
[ 8 4 2]
[ 9 3 7]]
[[ 7 8 9]
[ 4 5 1]
[ 2 6 10]]
[[ 7 5 9]
[ 6 3 4]
[ 2 10 1]]
[[ 9 3 5]
[ 1 6 2]
[10 8 4]]
[[ 1 7 4]
[ 6 5 2]
[10 9 3]]
[[ 8 7 3]
[ 5 10 2]
[ 1 6 4]]
[[ 7 3 9]
[ 8 2 4]
[ 6 10 1]]
[[ 6 7 4]
[ 2 9 3]
[10 1 5]]
[[ 3 1 2]
[ 4 5 7]
[10 8 6]]
[[ 9 5 7]
[ 1 8 3]
[ 4 2 6]]
```
阅读全文