请教如何在taichi scope 用i32参数作为数组下标访问python scope 的数组

A=np.array([1,2,3,4])
@ti.kernel
def qwer():
a=2
print(A[a])

qwer()

IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

你可以尝试用 ti.static()a 变成一个编译期常量:

@ti.kernel
def qwer():
    a = ti.static(2)
    print(A[a])  # output: 3