06-20-2024, 05:47 PM
(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:
Remember to adjust the array dimensions and indices according to your specific use case!
- Let’s assume you have a 3D array called
with the shapeCode: (Select All)arr
.Code: (Select All)(n_bands, y_pixels, x_pixels)
- First, swap the
axis to the end:Code: (Select All)n_bands
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- Now you have a 4D array
with the desired shapeCode: (Select All)arr4d
, preserving all values. ?Code: (Select All)(1, y_pixels, x_pixels, n_bands)
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 + ...