当前位置:网站首页>IndexError: index 9 is out of bounds for axis 0 with size 9;数组下标溢出问题
IndexError: index 9 is out of bounds for axis 0 with size 9;数组下标溢出问题
2022-08-11 05:29:00 【zhangkai__】
IndexError: index 9 is out of bounds for axis 0 with size 9
今天在写一个机器学习算法的时候遇到了这样一个问题,算法原型的一部分是想要求样本数据特征平均值,本身是很简单,但是报出一个
IndexError: index 9 is out of bounds for axis 0 with size 9 错误。。。。翻译一下:索引9超出轴0的大小为9的界限。
问题的解决:
首先我要处理的训练集类似这样:(只是一个部分的比喻)
数据集特征个数为9,因为是表格是二维的,我在设置循环时候错误的写成了X_train[j],[i], 因为x[n],[m]代表第n+1行的第m+1个数,前面X_train[j],[i], 写错了i,和j的位置,i最大43500 肯定远超过了9,所以报了个大大的红!!!
- 改正后的代码如下,X_train[i],[j],才是正解。。
for j in range(len(X_train[0])):#j(0-9)
valsum=0
for i in range(len(X_train)):#i(0-43500)
valsum+=X_train[i][j]
valsum/=len(X_train)
avg.append(valsum)
另外记录一下,当想取指定长度的浮点数,可以使用round()函数;
a = 3.1415926
print(round(a, 4))
# 3.142 会自动进位4舍5入
边栏推荐
- Vscode remote connection server terminal zsh+Oh-my-zsh + Powerlevel10 + Autosuggestions + Autojump + Syntax-highlighting
- Jetpack之dataBinding
- ARM 汇编指令 ADR 与 LDR 使用
- 深度学习Matlab工具箱代码注释
- 星盟-pwn-babyfmt
- 8-byte standard request parsing during USB enumeration
- OpenMLDB:线上线下一致的生产级特征计算平台
- Compilation exception resolution
- OpenMLDB Pulsar Connector:高效打通实时数据到特征工程
- helm安装
猜你喜欢
随机推荐
[Meetup Preview] OpenMLDB+OneFlow: Link feature engineering to model training to accelerate machine learning model development
Real-time Feature Computing Platform Architecture Methodology and Practice Based on OpenMLDB
Intelligent risk control China design and fall to the ground
PAT乙级刷题之路
使用c语言实现井字棋(有源码,可以直接运行)
Day 83
2021-09-11 C语言 变量与内存分配
Pinyougou project combat notes
js learning advanced (event senior pink teacher teaching notes)
Scene-driven feature calculation method OpenMLDB, efficient implementation of "calculate first use"
The role of the port
智能风控中台设计与落地
Jetpack use exception problem collection
The official website of OpenMLDB is upgraded, and the mysterious contributor map will take you to advance quickly
贡献者任务第三期精彩来袭
论文解读TransFG: A Transformer Architecture for Fine-grained Recognition
Day 69
【无标题】
经纬度求距离
Asis2016 books null off by one