sorting a 3D array

Recommended Posts

I know you can sort a 1d , 2d array using _ArraySort command, but i have a 3d array

can i sort it ?

thanks

say for example i want to sort it using this element \$[\$A][\$B][3]

and i want to write down the resault if this array sorted by this element where a=0 to 50 and b = 0 to 400

Edited by mrbig1479

Share on other sites

I know you can sort a 1d , 2d array using _ArraySort command, but i have a 3d array

can i sort it ?

thanks

say for example i want to sort it using this element \$[\$A][\$B][3]

and i want to write down the resault if this array sorted by this element where a=0 to 50 and b = 0 to 400

The problem with 3D array sort is rules. You have to specify what you want moved, and what relationships in the 1st and 2nd dimensions you want preserved. Do you want the 1st dimensions moved (\$A) preserving the 2nd dimension order under it?

Let's say the first four elements found in the sort are:

[3][145][3] = 0

[1][321][3] = 1

[5][9][3] = 2

[2][58][3] = 3

All other [\$A][\$B][3] combinations = 4

Now, what do you want moved where, based on that result? There are many ways to do it, and they will all be very situational. So it is not trivial to write a generic 3D sort that isn't so singularly application specific that it would be useless to any other application.

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share on other sites

The problem with 3D array sort is rules. You have to specify what you want moved, and what relationships in the 1st and 2nd dimensions you want preserved. Do you want the 1st dimensions moved (\$A) preserving the 2nd dimension order under it?

Let's say the first four elements found in the sort are:

[3][145][3] = 0

[1][321][3] = 1

[5][9][3] = 2

[2][58][3] = 3

All other [\$A][\$B][3] combinations = 4

Now, what do you want moved where, based on that result? There are many ways to do it, and they will all be very situational. So it is not trivial to write a generic 3D sort that isn't so singularly application specific that it would be useless to any other application.

Well i want to sort the array like this

from 0 to 4.6

[3][145][3] = 0

[1][321][3] = 1

[1][311][3] = 1.1

[5][9][3] = 2.5

[2][58][3] = 3

[15][58][3] = 4.6

etc..

its by the 3rd element of that array

and i want to write down the sorted array in a file for example

Share on other sites

Well i want to sort the array like this

from 0 to 4.6

[3][145][3] = 0

[1][321][3] = 1

[1][311][3] = 1.1

[5][9][3] = 2.5

[2][58][3] = 3

[15][58][3] = 4.6

etc..

its by the 3rd element of that array

and i want to write down the sorted array in a file for example

You didn't answer my question of where you would want those elements MOVED to within the 3D array to achieve the sort, but that may be moot if you are not interested in acutally sorting the array. It sound from your last post like all you want is a collection of all the [x][y][3] elements extracted and sorted. That would be pretty easy:
```#include <Array.au3>

; Create 3D array
Global \$av3DArray[51][401][4]

; Whatever unknown process fills [\$x][\$y][3] with values, here random numbers
For \$x = 0 To UBound(\$av3DArray) - 1
For \$y = 0 To UBound(\$av3DArray, 2) - 1
\$av3DArray[\$x][\$y][3] = Random()
Next
Next

; Extract the values and display
Global \$avSort[UBound(\$av3DArray) * UBound(\$av3DArray, 2)]
Global \$i = 0
For \$x = 0 To UBound(\$av3DArray) - 1
For \$y = 0 To UBound(\$av3DArray, 2) - 1
\$avSort[\$i] = \$av3DArray[\$x][\$y][3]
\$i += 1
Next
Next
_ArrayDisplay(\$avSort, "Before Sort")

; Sort and display
_ArraySort(\$avSort)
_ArrayDisplay(\$avSort, "After Sort")```

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share on other sites

Well i want to sort the array like this

from 0 to 4.6

[3][145][3] = 0

[1][321][3] = 1

[1][311][3] = 1.1

[5][9][3] = 2.5

[2][58][3] = 3

[15][58][3] = 4.6

etc..

its by the 3rd element of that array

and i want to write down the sorted array in a file for example

Well beaten by PsaltyDS, but mine does show the elements and the values

```;sort by third element index 3
#include <array.au3>
Dim \$Array[50][400][7]
Dim \$aSort[50 * 400][2]

For \$n = 0 To 50 - 1
For \$p = 0 To 400 - 1
\$Array[\$n][\$p][3] = Random(0, 100000)
Next
Next

For \$n = 0 To 50 - 1
For \$p = 0 To 400 - 1
\$aSort[400 * \$n + \$p][0] = \$Array[\$n][\$p][3]
\$aSort[400 * \$n + \$p][1] = \$n & ',' & \$p
Next
Next

;_ArrayDisplay(\$aSort)
_ArraySort(\$aSort, 0, 0, 0, 0)
;_ArrayDisplay(\$aSort)

\$hF = FileOpen("logfile.txt", 2)

For \$n = 0 To 50 * 400 - 1
\$next = StringSplit(\$aSort[\$n][1], ",")
FileWriteLine(\$hF, "[" & \$next[1] & "][" & \$next[2] & "] = " & \$aSort[\$n][0])
Next
FileClose(\$hF)```

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share on other sites

Thank you very much , both of you...

Create an account

Register a new account