Home > Enterprise >  Slice multidimensional array
Slice multidimensional array

Time:08-16

I have an array (images_lst) having shape (250,500,500), it is basically a list of 250 images having dimensions 500X500. How do I select only the first dimension of the array to use it in a loop given below

for n in images_lst:
    p=n
    print(p)
    #some other lines in the loop which works fine
        while p>=10:
        p =1
        sys.exit()
        #basically I want to exit the code after the 10th image

when I print p I get an array

[[[19 18 27 ......88 90 84]]]

what I want to print is

0 1 2 ... 10

Also, the while loop will not work here because the array has more than one element and is unable to perform the Boolean expression p>=10.

CodePudding user response:

I guess you have a wrong operator... while p>=10: should be < But i'm not sure :D I'm beginner, but it seems possible

CodePudding user response:

When you print p you are printing an array of arrays. It will be the first row of the images_lst 3D array.

Try this to iterate over each dimension and then perform the comparison against each innermost element:

for x in images_lst:
    for y in x:
        for z in y:
            # if statement here 
            break
  • Related