如何将Numpy数组数组存储在CSV文件中?

发布于 2025-01-31 02:39:43 字数 699 浏览 0 评论 0原文

我有一个图像名称,图像路径,它是对应的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄居人 2025-02-07 02:39:43

您可以使用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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文