Python:獲取列表List中給定索引的元素,不可以使用List的存儲索引。A是list,B也是list A[B]是有問題的。

import numpy as np
# a = np.array([[1,2],[2,3],[3,4],[4,5]])
a = [[1,2],[2,3],[3,4],[4,5]]
b = np.array([1,2,3])
print(a[b])

返回的錯誤是:

Traceback (most recent call last):
  File "C:/Users/DeniuHe/PycharmProjects/Project1/demo_test_0035.py", line 5, in <module>
    print(a[b])
TypeError: list indices must be integers or slices, not list
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章