0

Hi So basically I got 2 arrays. For the sake of simplicity the following:

array_notepad = []
array_images = []

Some magic happens and they are populated, i.e. data is loaded, for array_notepad data is read from a notepad file whilst array_images is populated with the RGB values from a folder containing images.

How do I use array_notepad as a label of array_images?

i.e. the label of array_images[0] is array_notepad[0], array_images[1] is array_notepad[1], array_images[1] is array_notepad[1], and so on until array_images[999] is array_notepad[999]

If it makes any difference I am using glob and cv2 to read the image data, whilst normal python file reader to read the content in the notepad.

Thanks a lot for your help!

xalalau
  • 1
  • 1
  • 6
  • Is there a reason why you are not using dictionary for this? – Ali Beyit Dec 12 '19 at 16:27
  • You may need to be more specific with your terminology. The code you showed are initialized as two lists. Then you mentioned you wanted to add labels. Is array_images[] a `pandas` dataframe or tensor? Are are they literally lists that you want to insert a new column (`array_notepad` into `array_images`)? – Jason K Lai Dec 12 '19 at 16:27

2 Answers2

0

Your question isn't entirely clear on what your expected output should be. You mention 'label' - to me it sounds like you're describing key-value pairs i.e. a dictionary.

In which case you should be able to use the zip function as described in this question: Convert two lists into a dictionary

Fab Dot
  • 504
  • 1
  • 5
  • 16
0

I hope you want to create a dictionary from 2 lists. If so you could do as follows.

array_notepad = ['label1', 'label2', 'label3']
array_images = ['rgb1', 'rgb2', 'rgb3']

d = { label: value for label, value in zip(array_notepad, array_images) }
d
Prince Francis
  • 2,995
  • 1
  • 14
  • 22