从numpy数组获取字符串

问题描述 投票:0回答:1

我正在寻找从以下numpy数组filename1.npy中提取test的简便方法:

array([['filename1.npy'],
       ['filename2.npy'],
       ['filename3.npy']],
      dtype=object)

我可以轻松地做到:str(test[1]),但是我仍然在其周围有那些括号['filename1.npy']。不过,我只想将名称插入np.load(path+'filename1.npy')

python arrays numpy
1个回答
0
投票

感谢您的快速回复:

test[0][0]

可以正常工作以获取filename1.npy。

要遍历所有名称,我现在使用:

for index in range(3):
    name = test[index]
    name = name[0]

    # load single file
    single_file = np.load(os.path.join(path,name))
© www.soinside.com 2019 - 2024. All rights reserved.