我有一个形状为 array1
的数组 (100, 256, 256)
,我正在尝试从数据中生成 2 个新数组。
两个数组都应该有唯一的值。
我尝试了以下代码,但它没有用唯一值填充 2 个数组
train_data = np.random.choice(array1.shape[0], 70)
test_data = np.random.choice(array1.shape[0], 30)
有什么建议吗?
答案 0 :(得分:2)
如果我理解你的问题,你可以像评论中提到的那样使用 np.random.shuffle
:
a = np.arange(100) #all indices from 0 to 99
np.random.shuffle(a) # shuffle the indices to make it random
train_indices = a[:70]
test_indices = a[70:]
train_data = array1[train_indices]
test_data = array1[test_indices]