0

i got a list of archives and a numpy np.array, the files in the list are the same correspondent in the numpy np.array "list"

I would like to know how to make a for loop that iterates in the items of the list like:

for i in range (list):
  get_items = (i, f) #when i is the first element in the list and f is the same in the numpy np.array

What I did so far is a for loop that iterates in the list

for i in range(list):
  get_items = the_class_i_need(i, _)

the "_" is where I got confused, because I called the numpy np.array. I know it's not working because I'm not calling the element by itself but the hole 200 itens in there. Somehow I think I was supposed to do a for loop inside a for loop but I learned what I larned all by myself and this is a hard thing to me. So thanks for the help already!!

  • What does your list and np array looks like? And what's the output you're aiming for? – SWEEPY Jan 10 '23 at 00:33
  • Are you asking how to iterate over two lists in a single for-loop? Than use `zip()`: https://stackoverflow.com/a/1663826/16496386 – phibel Jan 10 '23 at 01:05
  • @SWEEPY, my list is a group of dicom images and the np array is all of the dicom images converted to pixels and stacked. The output I'm aiming is a way to get the first item in both to run in a class that denoises the image so it can be used – Guilherme de Lima Schwaikartt Jan 10 '23 at 02:00

1 Answers1

0

As mentioned above, you can iterate through your list and np array in parallel using zip() function by doing :

for i, f in zip(list_archives, np_archives):
    get_items = the_class_i_need(i, f)

For example :

list_archives = [1, 2, 3, 4]
np_archives = np.array(['A', 'B', 'C', 'D'])

for i, f in zip(list_archives, np_archives):
    print(i, f)

# Output
# 1 A
# 2 B
# 3 C
# 4 D
SWEEPY
  • 589
  • 1
  • 6
  • 20