Jump to content

Array Column Delete


jugador
 Share

Recommended Posts

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 by jugador
Link to comment
Share on other sites

  • Moderators

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!

Link to comment
Share on other sites

@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 :whistle:  me.

Link to comment
Share on other sites

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.

9856324_deletekeep.png.6691bcc092efbf8696531b2d48eeab37.png

; 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

 

 

Link to comment
Share on other sites

  • 4 weeks later...

__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 by jugador
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...