[Python] How to store an image in pandas dataframe column?

Discussão em 'Python' iniciado por Stack, Abril 6, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following line of code.

    v = chemcepterize_mol(mol, embed=10, res=0.2)


    The function chemcepterize_mol takes some arguments like mol, embed, res. This function chemcepterize_mol return a value which i store in v which is an ordinary variable.

    This v is actually a vector representing three dimensional image.

    The shape of the v is as follows.

    print(v.shape)
    (100, 100, 4)


    100X100 pixels image with 4 channels.

    When I show this image, It looks like below.

    plt.imshow(v[:,:,:3])


    [​IMG]

    Up to this point, it works fine. But I have few of these types of images (3 dimensional vectors) which I need to store in my dataframe. That means, I need to call this function chemcepterize_mol few times, lets say 10 times to obtain 10 images.

    For that I wrote a for loop like this below.

    v = np.ndarray(shape=(100,100, 4,1))
    for x in range(10):

    v[x]=chemcepterize_mol(data["mol"][x],embed=10,res=0.2)


    Here, data["mol"][x]is the x entry of the column mol in my data frame data. For each of these data["mol"][x] values , the chemcepterize_mol will give me a different 3 dimensional vector which I need to store.

    I declared v = np.ndarray(shape=(100,100, 4,1)) so that in it's last dimension, I can store all my vectors (images), but it it given me this error.

    ValueError: could not broadcast input array from shape (100,100,4) into shape (100,4,1)


    How can I store all my vectors in some array or preferably in separate pandas data frame column.

    Continue reading...

Compartilhe esta Página