19 lines
460 B
Python
19 lines
460 B
Python
import numpy as np
|
||
|
||
# 生成100个随机数
|
||
data = np.random.rand(100)
|
||
# 对数据排序
|
||
data_sorted = np.sort(data)
|
||
# 将数据分为10份
|
||
data_split = np.split(data_sorted, 10)
|
||
|
||
# 生成10个随机索引,每个索引指向对应的数据分组
|
||
indices = np.random.randint(0, 10, size=10)
|
||
print(indices)
|
||
# 遍历索引,获取每一份数据的一个随机值
|
||
result = []
|
||
for i in indices:
|
||
result.append(np.random.choice(data_split[i]))
|
||
|
||
print(result)
|