satanico64 Posted January 8, 2016 Posted January 8, 2016 hi guys ! nice to see you again !i've just spend hours on the forum, until it went down... : \so forum is back and me too, and here's the problemProblem with array :i've a 2d array, from which i want to extract 1 row with all it's value , to get a 1d array.Method:1 i search my value => got $index in array2 i _arrayextract 1 row > But it still make a 2d array (1 value by column)3 i arraytranspose => And it should make 1 d arraybut not.... let's have a look with simplified codeThanks to explain where i am wrong ?ps: I've just updated latest stable version of autoit because i had bug with extract column zero . it's ok now but my transpose does'nt seems to work anymore...thanksnicolas.Simple code:#include <Array.au3> Local $aArray[4][4] For $i = 0 To 3 For $j = 0 To 3 $aArray[$i][$j] = $i & $j Next Next _ArrayDisplay($aArray, "Original") ; >Display a 2d array Local $aExtract = _ArrayExtract($aArray, 0, 0) ; for me it extract 1 row but still 2d array _ArrayDisplay($aExtract, "Row 0-0") ConsoleWrite('dimension:' & UBound($aExtract, $UBOUND_DIMENSIONS ) & @CRLF ) ; It's a 2d array _ArrayTranspose($aExtract) ; I thought i should obtain a 1d array with that _ArrayDisplay($aExtract, "Row 0-0") ConsoleWrite('dimension:' & UBound($aExtract, $UBOUND_DIMENSIONS ) & @CRLF ) ; It's a 2d array
water Posted January 8, 2016 Posted January 8, 2016 _ArrayTranspose only swaps rows and columns but it doesn't change the number of dimensions. Seems you have to code it yourself.But this is no brain surgery. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted January 8, 2016 Posted January 8, 2016 Example:#include <Array.au3> Global $aArray2D[3][3] = [[11, 12, 13], [21, 22, 23], [31, 32, 33]] _ArrayDisplay($aArray2D) Global $aArray1D[1] Global $iIndex2D = 1 ReDim $aArray1D[UBound($aArray2D, 2)] For $i = 0 to UBound($aArray2D, 2) - 1 $aArray1D[$i] = $aArray2D[$iIndex2D][$i] Next _ArrayDisplay($aArray1D) My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
satanico64 Posted January 8, 2016 Author Posted January 8, 2016 hmm i humbly disagree (or i simply don't understand), If you take a 1D array with more than 1 record, and you swap it make a 2d array.If you swap again it should make a 1D array. (in our case where it has only one row) i take the help file from _ArrayTranspose, it indicate that it transpose array from 1d to 2d, and 2d to 1dthe example provided, i just add consolewrite dimensions and remove first example: #include <Array.au3> Local $aArray[5] = [1, 2, 3, 4, 5] ConsoleWrite('Initial 1D dimension :' & UBound($aArray, $UBOUND_DIMENSIONS ) & @CRLF ) _ArrayDisplay($aArray, "Original 1D") _ArrayTranspose($aArray) ConsoleWrite('dimension after transpose of 1D array :' & UBound($aArray, $UBOUND_DIMENSIONS ) & @CRLF ) _ArrayDisplay($aArray, "Transposed to 2D") _ArrayTranspose($aArray) ConsoleWrite('dimension after transpose of 2D array :' & UBound($aArray, $UBOUND_DIMENSIONS ) & @CRLF ) _ArrayDisplay($aArray, "Re-transposed to 1D") ;>>>> BUT IT FAILED HERE, still 2D where am i wrong ?ps: Thanks Water for taking a look, i'm honored, your work helped me a lot, many times.
water Posted January 8, 2016 Posted January 8, 2016 As I see it the example is misleading/wrong. The UDF is not able to tell if a 2D array with only a single line should be a 1D array or a 2D array with only one column after transposing.Will discuss this with the Devs. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
satanico64 Posted January 8, 2016 Author Posted January 8, 2016 i've just install old autoit version (3.3.12.0) on other computer, and the same last script transpose from 2d to 1d Nicolas.
satanico64 Posted January 8, 2016 Author Posted January 8, 2016 (edited) by the way, for my original problem another solution is:1 find index2 transpose => still 2D but i 'll extract 1 column and not a row3 extract one column => 1d array. Edited January 8, 2016 by satanico64 missed one character
water Posted January 8, 2016 Posted January 8, 2016 i've just install old autoit version (3.3.12.0) on other computer, and the same last script transpose from 2d to 1dThanks for that info.Already passed to the Devs. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted January 9, 2016 Posted January 9, 2016 Melba23 has already created this modification. There is a new parameter to specify if you want to get a 1D or 2D array in this special case.Could you please check and post your findings?expandcollapse popup#include <Array.au3> Local $aArray[5] = [1, 2, 3, 4, 5] _ArrayDisplay($aArray, "Original 1D") _ArrayTranspose_Mod($aArray) _ArrayDisplay($aArray, "Transposed to 2D") _ArrayTranspose_Mod($aArray) _ArrayDisplay($aArray, "Re-transposed as 2D") _ArrayTranspose_Mod($aArray) _ArrayDisplay($aArray, "Still 2D") _ArrayTranspose_Mod($aArray, True) ; Force 1D return _ArrayDisplay($aArray, "Re-transposed to 1D") Func _ArrayTranspose_Mod(ByRef $aArray, $bForce1D = False) Switch UBound($aArray, 0) Case 0 Return SetError(2, 0, 0) Case 1 Local $aTemp[1][UBound($aArray)] For $i = 0 To UBound($aArray) - 1 $aTemp[0][$i] = $aArray[$i] Next $aArray = $aTemp Case 2 Local $iDim_1 = UBound($aArray, 1), $iDim_2 = UBound($aArray, 2) If $iDim_1 <> $iDim_2 Then If $iDim_1 = 1 And $bForce1D Then ; If only 1 row and 1D return forced Local $aTemp[$iDim_2] For $i = 0 To $iDim_2 - 1 $aTemp[$i] = $aArray[0][$i] Next Else ; Stay as 2D Local $aTemp[$iDim_2][$iDim_1] For $i = 0 To $iDim_1 - 1 For $j = 0 To $iDim_2 - 1 $aTemp[$j][$i] = $aArray[$i][$j] Next Next EndIf $aArray = $aTemp Else ; optimimal method for a square grid Local $vElement For $i = 0 To $iDim_1 - 1 For $j = $i + 1 To $iDim_2 - 1 $vElement = $aArray[$i][$j] $aArray[$i][$j] = $aArray[$j][$i] $aArray[$j][$i] = $vElement Next Next EndIf Case Else Return SetError(1, 0, 0) EndSwitch Return 1 EndFunc ;==>_ArrayTranspose My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
satanico64 Posted January 10, 2016 Author Posted January 10, 2016 It works like a charm.Thanks all of you.And I wish you a happy new year from Bordeaux, France.Nicolas.my test code:expandcollapse popup#include <Array.au3> Local $aArray[5] = [1, 2, 3, 4, 5] _ArrayDisplay($aArray, "Original 1D") ConsoleWrite('Initial 1D dimension :' & UBound($aArray, $UBOUND_DIMENSIONS ) & @CRLF ) _ArrayTranspose_Mod($aArray) ConsoleWrite('Dimension Transposed to 2D :' & UBound($aArray, $UBOUND_DIMENSIONS ) & @CRLF ) _ArrayDisplay($aArray, "Transposed to 2D") _ArrayTranspose_Mod($aArray) ; still 2D, but expected. ConsoleWrite('re transpose to initial without force, dimension :' & UBound($aArray, $UBOUND_DIMENSIONS ) & @CRLF ) _ArrayDisplay($aArray, "Re-transposed as initial without force ") _ArrayTranspose_Mod($aArray) ConsoleWrite('re Transposed to 2D :' & UBound($aArray, $UBOUND_DIMENSIONS ) & @CRLF ) ;obvsiouly 2D _ArrayDisplay($aArray, "Transposed to 2D again") _ArrayTranspose_Mod($aArray, True) ; Force 1D return => Now 1D. Hoped. Obtained. Impressed. ConsoleWrite('Transposed to 1d with force :' & UBound($aArray, $UBOUND_DIMENSIONS ) & @CRLF ) _ArrayDisplay($aArray, "Transposed to initial") Func _ArrayTranspose_Mod(ByRef $aArray, $bForce1D = False) Switch UBound($aArray, 0) Case 0 Return SetError(2, 0, 0) Case 1 Local $aTemp[1][UBound($aArray)] For $i = 0 To UBound($aArray) - 1 $aTemp[0][$i] = $aArray[$i] Next $aArray = $aTemp Case 2 Local $iDim_1 = UBound($aArray, 1), $iDim_2 = UBound($aArray, 2) If $iDim_1 <> $iDim_2 Then If $iDim_1 = 1 And $bForce1D Then ; If only 1 row and 1D return forced Local $aTemp[$iDim_2] For $i = 0 To $iDim_2 - 1 $aTemp[$i] = $aArray[0][$i] Next Else ; Stay as 2D Local $aTemp[$iDim_2][$iDim_1] For $i = 0 To $iDim_1 - 1 For $j = 0 To $iDim_2 - 1 $aTemp[$j][$i] = $aArray[$i][$j] Next Next EndIf $aArray = $aTemp Else ; optimimal method for a square grid Local $vElement For $i = 0 To $iDim_1 - 1 For $j = $i + 1 To $iDim_2 - 1 $vElement = $aArray[$i][$j] $aArray[$i][$j] = $aArray[$j][$i] $aArray[$j][$i] = $vElement Next Next EndIf Case Else Return SetError(1, 0, 0) EndSwitch Return 1 EndFunc ;==>_ArrayTranspose
water Posted January 10, 2016 Posted January 10, 2016 Thanks for testing.I'm glad this little modification solved your problem.Will tell Melba about the result so he might include it in the Array UDF.Happy new year from Lake Constance! My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now