Jump to content

Removing a dimension from an array


Recommended Posts

Unfortunately

ReDim $aArray[5]
doesn't work. As soon as you change the number of dimensions the complete content of the array is dropped.

According to the help file: "The number of dimensions must remain the same, or the old array will be forgotten during the ReDim."

omg ur right... XD. Just checked the output, and all the data was cleared from the array after the ReDim. First method out the window then.
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Is .007 seconds really that much of a difference?

It's actually .07 seconds =P. 7/100ths of a second doesn't mean much, however the margin is 35%, which is significant if the array was huge and/or if the system is running low-end hardware (think Pentium II/III/IV Single-Cores @ < 2.2GHz, and 512mb RAM)

Edited by mechaflash213
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

It's actually .07 seconds =P. 7/100ths of a second doesn't mean much, however the margin is 35%, which is significant if the array was huge and/or if the system is running low-end hardware (think Pentium II/III/IV Single-Cores @ < 2.6GHz, and 512mb RAM)

It's actually 0.006303 seconds (0.018022 - 0.011719), your figures from your post copied verbatim. Yes, the difference is 35%, but in numbers too small to matter. You're doing this on an array with almost 4000 "rows", that's pretty substantial. Plus, if you're running it on $hit hardware, you should expect EVERYTHING to run slower.

I still say, if they both worked the same, and the difference was 0.006303, you could reasonably use either one.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

It's actually 0.006303 seconds (0.018022 - 0.011719)

Whoops... I'm trippin' :D

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

I got a bit confused by some of the posts in this thread yesterday. Anyway I decided to see how much slower using _ArraySwap would be, The difference is just over 5 times slower. So mechaflash213 - it does make quite a difference

#include <Array.au3>

Dim $aArray[1][2] = [[0,0]]
$iTimer = TimerInit()

; Swapping Elements
For $i = 1 To 10000
    _ArraySwap($aArray[0][0], $aArray[0][1])
Next
ConsoleWrite(TimerDiff($iTimer) & @LF)

$iTimer = TimerInit()

; Overwriting Elements
For $i = 1 To 10000
    $aArray[0][0] = $aArray[0][1]
Next
ConsoleWrite(TimerDiff($iTimer) & @LF)

swapping 2 columns ... 55.981137267446

overwriting 1 column .. 10.0557473086663

Edited by czardas
Link to comment
Share on other sites

Here a crazy and ineffective idea:

#include <Array.au3>
Global $aTest[4][2] = [ [1, 2], _
                                        [4, 5], _
                                        [7, 8], _
                                        [10, 11]]

$aRot = ArrayRotate($aTest, -180)
ReDim $aRot[UBound($aRot)][1]
$aRot = ArrayRotate($aRot, -180)
_ArrayDisplay($aRot)

Func ArrayRotate($aArray, $iDeg) ;coded by UEZ 2012 build 2012-02-15
    If Not IsArray($aArray) Then Return SetError(1, 0, 0) ;not an array
    If Not UBound($aArray, 0) = 2 Then Return SetError(2, 0, 0) ;not a 2D array
    If Mod($iDeg, 90) Then Return SetError(3, 0, 0) ;only 90° rotations allowed
    Local $i, $j, $k = 0, $l = 0
    Switch $iDeg
        Case 90, -270
            Local $aRotated[UBound($aArray, 2)][UBound($aArray)]
            For $i = 0 To UBound($aArray, 2) - 1
                For $j = UBound($aArray) -1 To 0 Step - 1
                    $aRotated[$i][$k] = $aArray[$j][$i]
                    $k += 1
                Next
                $k = 0
            Next
            Return $aRotated
        Case 270, -90
            Local $aRotated[UBound($aArray, 2)][UBound($aArray)]
            For $i = UBound($aArray, 2) - 1 To 0 Step - 1
                For $j = 0 To UBound($aArray) - 1
                    $aRotated[$l][$k] = $aArray[$j][$i]
                    $k += 1
                Next
                $l += 1
                $k = 0
            Next
            Return $aRotated
        Case 180, -180
            Local $aRotated[UBound($aArray)][UBound($aArray, 2)]
            For $i = UBound($aArray) - 1 To 0 Step - 1
                For $j = UBound($aArray, 2) - 1 To 0 Step - 1
                    $aRotated[$l][$k] = $aArray[$i][$j]
                    $k += 1
                Next
                $l += 1
                $k = 0
            Next
            Return $aRotated
    EndSwitch
EndFunc

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

UEZ - Crazy or not, I very much like it. Especially the 90 rotation. :huh:

I have in mind a project to do this with multiline text (adding trailing white spaces to form a rectangle of characters). Should be fun to play with.

I now have it working, but my first attempt contained a stupid error, and the days of the week rotated 90 degrees clockwise returned.

dardum
dardum
dardum
dardum
dardum
dardum

I thought it was trying to tell me something. :D .

Edited by czardas
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...