Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug when redimensioning multi-dimension arrays?
#20
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.
Reply


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



Users browsing this thread: 1 Guest(s)