import numpy as np
targets = np.zeros((3,1), dtype=int)
print(targets)
targets = [[1],
[2],
[3]]
print(targets)
rand_idx = np.random.permutation(3)
print(rand_idx)
targets = np.array(targets)[rand_idx]
print(targets)
使用 np.random.permutation(num)打乱数据,生成索引列表 可以直接传入,产生如下错误
TypeError: only integer scalar arrays can be converted to a scalar index
将targets[rand_idx]
改为np.array(targets)[rand_idx]