前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >only integer scalar arrays can be converted to a scalar index

only integer scalar arrays can be converted to a scalar index

作者头像
演化计算与人工智能
发布2020-08-14 11:30:15
2.3K0
发布2020-08-14 11:30:15
举报

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

  • 使用np.random.choice创建list,使用这个List作为Data[] List对象的索引。
  • 出现TypeError: only integer scalar arrays can be converted to a scalar index错误。
  • 原始语句:
代码语言:javascript
复制
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]
代码语言:javascript
复制
train_indices = np.random.choice(35444, 24500, replace=False)
writer.writerows(np.array(data)[train_indices])
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-05-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 DrawSky 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • TypeError: only integer scalar arrays can be converted to a scalar index
    • 解决方案
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档