jugador Posted July 12, 2021 Posted July 12, 2021 (edited) May not be useful for others but I do it this way when needed to delete lots of column. #include <Array.au3> #include "ArrayDeleteCol.au3" Local $x_Array[][] = [[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35]] _ArrayDisplay($x_Array) Local $x_ColumnToDelete = '1;28;6-9;13;13;15;18-24;4;30' __Array_DeleteColumn($x_Array, $x_ColumnToDelete) _ArrayDisplay($x_Array) @pixelsearch version ArrayDeleteCol.au3 for __Array_DeleteColumn (Version 3)https://www.autoitscript.com/forum/topic/206244-array-column-delete/?do=findComment&comment=1487010 Edited March 2, 2022 by jugador pixelsearch 1
Moderators JLogan3o13 Posted July 12, 2021 Moderators Posted July 12, 2021 Just out of curiosity, how does this differ - or what advantages are there - over the included _ArrayColDelete function? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
jugador Posted July 13, 2021 Author Posted July 13, 2021 @JLogan3o13 Have you tried the code? I guess not Can we pass list of column (like $x_ColumnToDelete in 1st post) want to delete in _ArrayColDelete. If yes I don’t know that, my mistake. Sometime I need to delete multiple columns many a times. It’s useful for such purpose for me.
dmob Posted July 14, 2021 Posted July 14, 2021 Nice. A little more "nice" would be to accept an array of values for $x_ColumnToDelete....
pixelsearch Posted July 14, 2021 Posted July 14, 2021 Hi @jugador, interesting topic indeed. May I suggest another approach to avoid several calls to _ArrayColDelete (17 in your example + 17 Redim etc...) . In fact there is no call to _ArrayColDelete in the code below. There's probably a couple of error checking to add but you'll get the idea and It should go faster (the more columns to delete, the faster it should be). Please indicate if something goes wrong with this approach. expandcollapse popup; Replace this : ;~ ;~ Sort a 1D Array ;~ _ArraySort($o_Column, 1) ;~ ;~ Delete Column ;~ For $i = 0 To UBound($o_Column) - 1 ;~ _ArrayColDelete($0_Array, $o_Column[$i]) ;~ Next ; With that : ; Sort a 1D Array of columns to delete (ascending, for $jStart and binary search to come) _ArraySort($o_Column) Local $jStart = $o_Column[0] ; 1st column to delete, i.e. don't touch column(s) on its left ConsoleWrite("$jStart = " & $jStart & @crlf) ; 1 in jugador's example _ArrayDisplay($o_Column, "To delete, asc") ; 17 cols ; Create a 1D array of columns to keep (ascending) Local $aColsToKeep[Ubound($0_Array, 2) - Ubound($o_Column)] ; 36 - 17 = 19 cols to keep ConsoleWrite("Ubound($aColsToKeep) = " & Ubound($aColsToKeep) & @crlf) ; 19 cols Local $iIndex = - 1 For $i = 0 To Ubound($0_Array, 2) - 1 If _ArrayBinarySearch($o_Column, $i) = -1 Then ; not found (-1) $iIndex += 1 ; 0+ $aColsToKeep[$iIndex] = $i EndIf Next _ArrayDisplay($aColsToKeep, "To keep, asc") ; 19 cols ; Position each element at its place, then 1 final Redim to delete rightmost column(s) For $i = 0 To Ubound($0_Array) - 1 For $j = $jStart To Ubound($aColsToKeep) - 1 $0_Array[$i][$j] = $0_Array[$i][$aColsToKeep[$j]] Next Next ReDim $0_Array[Ubound($0_Array)][Ubound($aColsToKeep)] ; 19 cols Musashi, jugador and dmob 3 "I think you are searching a bug where there is no bug... don't listen to bad advice."
dmob Posted July 14, 2021 Posted July 14, 2021 @pixelsearch, always impressive how you dig deep to optimise code pixelsearch 1
jugador Posted July 14, 2021 Author Posted July 14, 2021 Thanks @pixelsearch uploaded new version as per your suggestion
Solution jugador Posted August 6, 2021 Author Solution Posted August 6, 2021 (edited) __Array_DeleteColumn (Version 3) ==> Speed improve . not deleting the modified version of @pixelsearch speed comparison with Autoit original _ArrayColDelete #include <Array.au3> #include "ArrayDeleteCol.au3" Local $x1_Array[][] = [[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35]] Local $x_ColumnToDelete = '1;28;6-9;13;13;15;18-24;4;30' Local $1_Timer = TimerInit() __Array_DeleteColumn($x1_Array, $x_ColumnToDelete) ConsoleWrite('Version 3: ' & TimerDiff($1_Timer) & @CRLF) Local $x3_Array[][] = [[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35]] Local $To_Delete[] = [30,28,24,23,22,21,20,19,18,15,13,9,8,7,6,4,1] Local $3_Timer = TimerInit() For $i = 0 To UBound($To_Delete) - 1 _ArrayColDelete($x3_Array, $To_Delete[$i]) Next ConsoleWrite('Original: ' & TimerDiff($3_Timer) & @CRLF) Quote Version 3: 0.420298933679558 Original: 0.735610623309268 ArrayDeleteCol.au3 Edited March 2, 2022 by jugador
jugador Posted Thursday at 06:31 PM Author Posted Thursday at 06:31 PM (edited) < below code for Delete selected Row not column > #include <Array.au3> Local $aArray_Base[20][4] For $i = 0 To UBound($aArray_Base) - 1 For $j = 0 To UBound($aArray_Base, 2) - 1 $aArray_Base[$i][$j] = $i & "-" & $j Next Next __Delete_Selected_Row($aArray_Base, '5,8,9,11,12,15,18') _ArrayDisplay($aArray_Base) Func __Delete_Selected_Row(Byref $aArray, $aRange) ;<<== $aRange must be in ascending order and use comma for multiple row If IsString($aRange) Then $aRange = StringSplit($aRange, ',', 2) Local $aflag = False Local $cMatch = 0 Local $Row_toDelete = $aRange[$cMatch] For $i = $aRange[$cMatch] To UBound($aArray, 1) - 1 IF ($Row_toDelete = $i) Then $aflag = True $cMatch += 1 If $cMatch < UBound($aRange) Then $Row_toDelete = $aRange[$cMatch] ContinueLoop Endif IF $aflag = True Then For $k = 0 To UBound($aArray, 2) - 1 $aArray[$i - $cMatch][$k] = $aArray[$i][$k] Next Endif Next Redim $aArray[UBound($aArray, 1) - $cMatch][UBound($aArray, 2)] EndFunc Edited 15 hours ago by jugador
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