import numpy as np import random

def createDataSet(): # 创建数据集 rdn1 = np.random.RandomState(1) points = [] i = 0 while True: x = round(rdn1.uniform(0, 100), 1) y = round(rdn1.uniform(0, 100), 1) if 45 <= x <= 55 and 45 <= y <= 55: continue points.append([x, y]) i += 1 if i == 600: break rdn3 = np.random.RandomState(2) demand = rdn3.randint(2, 11, 600) # 需求 return np.array(points), demand

Alldataset, Alldemand = createDataSet() ### 恒定所有客户的数据集

从Alldataset和Alldemand里面随机选择三百个不重复的数据,其中dataset输出类型为数组,demand为列表

dataset_indices = random.sample(range(len(Alldataset)), 300) # 从Alldataset中随机选取300个数据的索引 dataset = Alldataset[dataset_indices] # 选取对应索引的数据 demand = Alldemand[dataset_indices] # 选取对应索引的需求数据

Python 随机选择数据集子集 - 300个不重复数据

原文地址: https://www.cveoy.top/t/topic/n2Zn 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录