代码之家  ›  专栏  ›  技术社区  ›  Simplicity

将标签附加到图像的矢量

  •  0
  • Simplicity  · 技术社区  · 8 年前

    我有一个 images 包含图像矢量和相关标签(即类)的列表。

    images.append([np.array(image_array_to_vector),np.array([label])])
    

    X 标签也在里面 y

    X = np.array([i[0] for i in images])
    y = [i[1] for i in images]
    

    然后我想存钱 在文本文件中,如下所示:

    X_to_text_file = np.savetxt('x.txt', X.reshape(np.shape(X)), fmt='%5f')
    

    上面的方法很好。我想做的更改是将标签附加到 十

    例如,我试过这样做:

    X = np.array([[i[0],i[1]] for i in images])
    

    但是,得到了以下错误:

    TypeError: Mismatch between array dtype ('object') and format specifier ('%5f %5f')
    

    而且,在尝试使用字典时,请执行以下操作:

    X = np.array([{i[1]:i[0]} for i in images])
    

    我得到这个错误:

    TypeError: unhashable type: 'numpy.ndarray'
    

    那么,是的,我如何将标签附加到向量上并保存在文本文件中呢?

    谢谢。

    1 回复  |  直到 8 年前
        1
  •  0
  •   abeagomez    8 年前

    X_to_text_file = np.savetxt('x.txt', X.reshape(np.shape(X)), fmt='%s')