我正在尝试使用预定义的变量来切片一个numpy数组。这样做是有效的:
b = fromfunction(lambda x,y: 10*x+y, (5,4),dtype=int) # Just some matrix
b[1:3,1:3]
# Output:
# array([[11, 12],
# [21, 22]])
但是我想做的是这样的:
slice = "1:3,1:3"
b[slice]
# Output:
# array([[11, 12],
# [21, 22]])
对于我来说,切片变量的类型并不重要,我只是举了一个字符串的例子。我该如何保存这样的切片限定符?