Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug when redimensioning multi-dimension arrays?
#22
(06-20-2024, 05:40 PM)Dimster Wrote: CoPilot says it can REDim a 3 Dim array into a $ dim array and preserve the values from the original array. Here is it's suggestion. 


Certainly! To redimension a 3D array to a 4D array while preserving all values in QB64pe, you can follow these steps:
  1. Let’s assume you have a 3D array called 
    Code: (Select All)
    arr
     with the shape 
    Code: (Select All)
    (n_bands, y_pixels, x_pixels)
    .
  2. First, swap the 
    Code: (Select All)
    n_bands
     axis to the end:
    Code: (Select All)
    DIM SHARED arr(1 TO n_bands, 1 TO y_pixels, 1 TO x_pixels)
    DIM SHARED arr4d(1 TO 1, 1 TO y_pixels, 1 TO x_pixels, 1 TO n_bands)

    FOR x = 1 TO x_pixels
        FOR y = 1 TO y_pixels
            FOR z = 1 TO n_bands
                arr4d(1, y, x, z) = arr(z, y, x)
            NEXT z
        NEXT y
    NEXT x
  3. Now you have a 4D array 
    Code: (Select All)
    arr4d
     with the desired shape 
    Code: (Select All)
    (1, y_pixels, x_pixels, n_bands)
    , preserving all values. ?
Remember to adjust the array dimensions and indices according to your specific use case! 




I'll have to see if Gemini can do it.

Yeah this is fine because there is no issue with trying to use the same array name with the different dimensions.

while on the subject you can make a 1 d array, a list, into many dimensions with a little math manipulation. As steve has shown, i think, in memory it's all 1 d.
b = b + ...
Reply


Messages In This Thread
RE: Bug when redimensioning multi-dimension arrays? - by bplus - 06-20-2024, 05:47 PM



Users browsing this thread: 10 Guest(s)