TypeError: only integer scalar arrays can be converted to a scalar index


TypeError: only integer scalar arrays can be converted to a scalar index

觉得有用的话,欢迎一起讨论相互学习~

我的微博我的github我的B站

  • 使用np.random.choice创建list,使用这个List作为Data[] List对象的索引。
  • 出现TypeError: only integer scalar arrays can be converted to a scalar index错误。
  • 原始语句:
train_indices = np.random.choice(35444, 24500, replace=False)
writer.writerows(data[train_indices])

TypeError: only integer scalar arrays can be converted to a scalar index错误。

解决方案

  • 将List转换为numpy数组即:np.array(data)[test_indices]
train_indices = np.random.choice(35444, 24500, replace=False)
writer.writerows(np.array(data)[train_indices])


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM