Python numpy - IndexError:数组的索引太多了

时间:2015-12-09 14:20:00

标签: numpy indexing

我对python很新,但这个例子对我不起作用。我相信它的意思是索引x,但我不是100%肯定。

import numpy as np

y = np.array([0,1,2,3,4,5,2,4,1,9])
x = np.array(['e','l','t','d','m','f','c','j','x','a'])

print
print
print "Y"
print type(y)
print y
print
print
print "X"
print type(x)
print x
print
print


result = x[0, y]

我得到的确切错误是

Traceback (most recent call last):
File "test.py", line 20, in <module>
result = x[0, y]
IndexError: too many indices for array

3 个答案:

答案 0 :(得分:0)

要从数组中获取值,必须使用x[index]。你不能在括号

中得到一个传递2个参数的值

答案 1 :(得分:0)

#Python 3.x from uber_rides.session import Session from uber_rides.client import UberRidesClient session = Session(server_token="something-special") client = UberRidesClient(session,sandbox_mode=True) #UberX product id product_id = '04a497f5-380d-47f2-bf1b-ad4cfdcb51f2' response = client.request_ride(product_id, 37.77, -122.41, 37.79, -122.41) ride_details = response.json ride_id = ride_details.get('request_id') response = client.update_sandbox_ride(ride_id, 'accepted') print(response) #error message ... ... uber_rides.errors.ClientError: The request contains bad syntax or cannot be filled due to a fault from the client sending the request. 不是多维数组。你必须将0添加到y:

x

答案 2 :(得分:0)

我明白我现在做错了什么,x应该是np.array([['e','l','t','d','m','f','c','j','x','a']]), 不是x = np.array(['e','l','t','d','m','f','c','j','x','a'])

感谢您的回复!

相关问题