我有一个这样的列表:
my_list = ['[:,y+1,x+1]', '[:,y+1,x-1]']
my_list[0]
给出:
'[:,y+1,x+1]'
如何获取唯一
[:,y+1,x+1]
为什么我需要这个:我正在尝试使用列表中的坐标读取 netcdf 文件,例如:
from netCDF4 import Dataset
fd = Dataset(ncfile,'r')
fd.variables['t2m']my_list[0]
其中 x 和 y 是预定义的。
最佳答案
在我看来,您似乎在寻找 np.s_
,它允许您“卡住”索引表达式。尝试
my_list = [np.s_[:,y+1,x+1], np.s_[:,y+1,x-1]]
关于python - 如何在没有字符串的情况下获取列表元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47324061/