I'd like to use a triple gun to output a triple array.

Asked 2 years ago, Updated 2 years ago, 14 views

I want to receive a 3D image and output it using a For statement.

But it's not been long since I started Python, so I'm confused about how to implement it.

Originally, the header value of the image should contain colmun and row values, but the images used do not have these values, so these values must be obtained in another way.

The size of the image currently being used is as long as the x-axis 500, the y-axis 500, and the z-axis 500.

x=500, y=500, z=500, Array[x][y][z]

But not all images have the same length, so you can't put those values in the envelope. The following are the shots you have created: I want to spin the first shell by the length of data[x], the second shell by the length of data[y], and the third shell by the length of data[z]. I think it's a long story. To put it simply, I want to find the maximum length of x, y, z that goes into the factor of a three-dimensional array. What should I do? Please give me a lot of help.

for x in range(0, 500):
    for y in range(100, 500):
        for z in range(220, 300):
            if data[x][y][z] != 0:

python

2022-09-21 15:46

2 Answers

The list of Pythons can tell you the length.

a = [ 1, 2, 3, 4, 5 ]
len(a)  # => 5

And if Array is a three-dimensional array, you can tour the loop without knowing the length. It is as follows:

for data_x in Array: # Array is a three-dimensional list
    For data_xy in data_x: #data_x is a two-dimensional list
        For data_xyz in data_xy: # data_xy is a one-dimensional list
             if data_xyz != 0:
                # # do what you want

If you need an index, write enumerate together.

for i, d in enumerate(lst):
    print(d, 'is the list', i, 'the first element)


2022-09-21 15:46

for x in data:
    for y in x:
        for z in y:
            if data[x][y][z] != 0:

I wrote the code like this, reflecting what you said. It says Memory Error.

for x in range(0, 500):
    for y in range(0, 500):
        for z in range(0,500):
            if data[x][y][z] != 0:

If the element in range is set to min and max in the array, no error is output separately. Is there a solution?


2022-09-21 15:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.