赞
踩
import numpy as np
imput=[[1,2],[3,4],[5,6],[7,0]]
shuff_args=np.arange(4)
np.random.shuffle(shuff_args)
imput_tra=imput[shuff_args]
print(imput_tra)
报错:TypeError: only integer scalar arrays can be converted to a scalar index
类型错误:只有整数标量数组才能转换为标量索引。此问题出现在最新的python、numpy版本中
改为以下代码:
imput=[[1,2],[3,4],[5,6],[7,0]]
shuff_args=np.arange(4)
np.random.shuffle(shuff_args)
imput_tra=np.array(imput)[shuff_args]
print(imput_tra)
输出结果:[[7 0] [5 6] [1 2] [3 4]]
解决问题
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。