如何将Numpy数组数组存储在CSV文件中?
我有一个图像名称,图像路径,它是对应的CNN特征向量(一个numpy数组)。并且有很多图像,这意味着我有一个名称,路径,向量的列表(每个列表是尺寸(1、2048、14、14)和float32的数据类型)。我必须有效地存储和访问。我正在考虑将其存储在CSV文件中。当我这样做时,我无法转换从str的numpy阵列。请让我知道如何进行此操作,谢谢。
data = pd.DataFrame(columns=['name', 'path', 'vector'])
data['name'] = image_names
data['path'] = image_paths
for i in range(len(image_paths)):
out = encoder(image_paths[i] #(1,2048,14,14)
data['vector'][i] = out
data.to_csv('encoding.csv', sep = ',', na_rep='Unknown')
dr =pd.read_csv('encoding.csv')
for i in range(dr.shape[0]):
c = dr['vector'][i]
C是str对象。不确定如何将其转换为numpy数组。
I have an image name, image path and it's corresponding cnn feature vector (a numpy array). And there are many images, meaning I have a list of names, paths, vectors (each being numpy array of dimension (1, 2048, 14, 14) and float32 as data type). I have to store and access in an efficient way. I was thinking of going with storing it in a csv file. When I did that, I am unable to convert back the numpy array from str. Kindly let me know how to proceed with this, thank you.
data = pd.DataFrame(columns=['name', 'path', 'vector'])
data['name'] = image_names
data['path'] = image_paths
for i in range(len(image_paths)):
out = encoder(image_paths[i] #(1,2048,14,14)
data['vector'][i] = out
data.to_csv('encoding.csv', sep = ',', na_rep='Unknown')
dr =pd.read_csv('encoding.csv')
for i in range(dr.shape[0]):
c = dr['vector'][i]
c is a str object. Unsure how to convert this to numpy array.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
numpy.save
保存numpy数组,如在这里。您可以将图像名称和图像路径保存为.json
文件(只需将.npy
文件的名称与相同的名称。 JSON
文件以允许更轻松的搜索)。You could save the numpy array using
numpy.save
as shown in the docs here. You could save the image name and image path as a.json
file (and just make the name of the.npy
file the same as the name as the.json
file to allow for easier searching).