python - IndexError:数组python的索引太多
问题描述
我的问题是从数组中获取除第一个元素之外的所有元素。我使用对象 p 和 q。
print(p.p)
print(q.p)
输出是:
(79, 12.37, 1.63, 2.3, 24.5, 88., 2.22, 2.45, 0.4, 1.9, 2.12, 0.89, 2.78, 342.)
(29, 12.33, 0.99, 1.95, 14.8, 136., 1.9, 1.85, 0.35, 2.76, 3.4, 1.06, 2.31, 750.)
如果我试试这个:
x = p.p[1:]
y = q.p[1:]
我收到此错误:
IndexError:数组的索引过多
我想我有这个错误,因为如果我尝试:
print(p.p(shape))
输出是:
()
我怎么解决这个问题 ?
更新:
class Point:
def __init__(self, p):
self.p = p #numpy
self.NN = []
self.active = True
解决方案
只需创建一个for
索引变量从 1 开始的循环:
for i in range(1, p.size):
print(p[i])
推荐阅读
- python - ML:R's Caret 中的大多数模型都可以在 Python 中使用吗?
- java - SupportMapFragment.getMapAsync-NullPointerException
- arrays - 如何在 Matlab 中快速生成多维数组(或张量)?
- javascript - 这个状态管理可以在react上做吗?
- ruby-on-rails-5 - Rspec 应该 AttributeDoesNotExistError
- yammer - Yammer API 根据组 ID #yammer 仅获取我的消息
- vb.net - 部分类继承基类
- javascript - 如何在非 Promise 函数中测试 Promise 回调?
- jenkins - 减少 Jenkinsfile 的缩进级别
- c++ - “程序以退出代码结束:0”出现在我的输出开头?