Jump to content
Sign in to follow this  
burger

Transpose Array

Recommended Posts

burger

How do you transpose an array?

Share this post


Link to post
Share on other sites
monoceres

_ArraySwap() :D


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
burger

Oh wow. Thanks! :D

Share this post


Link to post
Share on other sites
junkew

Depends on what you want to do but below is a basic algorithm to do this.

dim $myArray[5][3]=[[1,2,3],[4,5,6],[7,8,9],[10,11,12],[13,14,15]]
dim $transposedarray[3][5]

;Transpone the array
for $i=0 to ubound($myArray,1)-1
    for $j=0 to ubound($myArray,2)-1
        $transposedArray[$j][$i]=$myArray[$i][$j]
    Next
Next

;Display the original one
for $i=0 to ubound($myArray,1)-1
    for $j=0 to ubound($myArray,2)-1
        consolewrite($myArray[$i][$j])
    Next
    consolewrite(@crlf)
Next

;Display the newone
for $i=0 to ubound($myArray,2)-1
    for $j=0 to ubound($myArray,1)-1
        consolewrite($transposedArray[$i][$j] & ";")
    Next
    consolewrite(@crlf)
Next

Share this post


Link to post
Share on other sites
burger

thanks. That's what I really needed.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×