2

I've a list of strings of images names and a numpy array with shape (4096,) features for each image.

for example the list of names:

img_list = ['img1', 'img2', 'img3']

features np.array

[array([0.        , 0.04688909, 0.05700445, ..., 0.        , 0.        ,
        0.        ], dtype=float32),
 array([0.        , 0.04688909, 0.05700445, ..., 0.        , 0.        ,
        0.        ], dtype=float32),
 array([0.03546982, 0.00310931, 0.        , ..., 0.        , 0.01513313,
        0.        ], dtype=float32)]

i want to add them to a pandas dataframe where the index would be the img name and features as 1 by column, something like this:

    f_1 f_2 f_3 ... f_4094  f_4095  f_4096
img 

The index from list of imgs is the same as the features array, so the img[0] has the features[0] array and so on.

How can I manage to merge them into a single dataframe shape N x 4096?

Thanks!

1 Answer 1

4

IIUC:

pd.DataFrame(features, img_list).add_prefix('f_')

MCVE

img_list = ['img1', 'img2', 'img3']
features = [np.array([1, 2, 3]), np.array([4, 5, 6]), np.array([7, 8, 9])]

df = pd.DataFrame(features, img_list).add_prefix('f_')
df

      f_0  f_1  f_2
img1    1    2    3
img2    4    5    6
img3    7    8    9
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.