TypeError: only integer scalar arrays can be converted to a scalar index
to be index can Only Integer TypeError Arrays
2023-09-11 14:15:01 时间
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错误。
- 原始语句:
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])
相关文章
- How much business logic should be allowed to exist in the controller layer?
- import data from excel to sql server
- How to use AutoMapper
- c#中@标志的作用 C#通过序列化实现深表复制 细说并发编程-TPL 大数据量下DataTable To List效率对比 【转载】C#工具类:实现文件操作File的工具类 异步多线程 Async .net 多线程 Thread ThreadPool Task .Net 反射学习
- uni-app - Refused to display ‘xxx‘ in a frame because an ancestor violates the following Content Sec
- number (2)编译错 (类的大小写错误) Filewriter cannot be resolved to a type
- maven org.springframework.web.filter.CharacterEncodingFilter cannot be cast to javax.servlet.Filter
- java.io.IOException: There appears to be a gap in the edit log. We expected txid ***, but got txid
- Server returns invalid timezone. Need to set ‘serverTimezone‘ property.解决方法
- pat 1092 To Buy or Not to Buy(20 分)
- Ruby on Rails Session 2: How to install Aptana Studio 3 on Ubuntu 12.04 LTS
- [LeetCode] Encode N-ary Tree to Binary Tree 将N叉树编码为二叉树
- Force bar chart Y axis scale to be integer-only