Allenfenqu/testttt2.py

19 lines
460 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)