list indices must be integers or slices, not tuple解决方案-python学习笔记

2,000 阅读1分钟

原因:多个[]的数组之间没加,逗号

image.png

源码:

import numpy as np

a = np.array([[1,2][3,4]])
print(a)

报错:

TypeError: list indices must be integers or slices, not tuple

修改方法: 在[1,2]后面加个英文逗号,

import numpy as np

a = np.array([[1,2],[3,4]])
print(a)