当前位置:   article > 正文

解决问题:only integer scalar arrays can be converted to a scalar index_np.concatenate only integer scalar arrays can be c

np.concatenate only integer scalar arrays can be converted to a scalar index
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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

报错: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)
  • 1
  • 2
  • 3
  • 4
  • 5

输出结果:[[7 0] [5 6] [1 2] [3 4]]

解决问题

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/700922
推荐阅读
相关标签
  

闽ICP备14008679号