Deye

Create an Array from column #

10 posts in this topic

#1 ·  Posted (edited)

Hi,

the reason i need this :
somewhere I read that _ArrayUnique() can crash the script when sending it through more then an 2D array

in some cases it does 

I only need to create a 1D Array from column #4  . . .

Edit:     never mind should be something like this i guess ..

Func _1D_ArrayFromColumn(ByRef $aArray, $iColumn = 0, $iCount = 1)
    Local $aArray1D = [UBound($aArray)]
    For $i = $iCount To UBound($aArray) - 1
        _ArrayAdd($a1D, $iColumn)
    Next
    Return $aArray1D
EndFunc   ;==>_1D_ArrayFromColumn

 

Edited by Deye

Share this post


Link to post
Share on other sites



#2 ·  Posted

Deye,

I don't think any distributed functions work on arrays with more than 2 dimensions.  The following strips column #4 from a 10 column "2D" array...

#include <array.au3>

; create and populate a 10 column 2D array

Local $a2Darray[10][10]

For $1 = 0 To UBound($a2Darray) - 1
    For $2 = 0 To UBound($a2Darray, 2) - 1
        $a2Darray[$2][$1] = StringFormat('%03i-%03i', $1, $2)
    Next
Next

_ArrayDisplay($a2Darray)

; create a 1D array from column #4 of the previous array

Local $a1Darray[UBound($a2Darray)]

For $1 = 0 To UBound($a2Darray) - 1
    $a1Darray[$1] = $a2Darray[$1][3]
Next

_ArrayDisplay($a1Darray, 'Column 4 of 2D array')

kylomas

1 person likes this

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#3 ·  Posted

Are you trying to create a unique column?

Share this post


Link to post
Share on other sites

#4 ·  Posted

yes 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Ah okay! I thought perhaps you might want to create a 2D array only containing unique rows, and functions for that exist. These are two different things. Carry on! :)

Edited by czardas
1 person likes this

Share this post


Link to post
Share on other sites

#6 ·  Posted

@czardas - yes, before the code was added the request was crystal clear...

Deye - the code you added and the code I posted do essentially the same thing (except that the array name in the array add is wrong).  Is your question answered?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#7 ·  Posted

    kylomas,

    Yes & thanks
 I've used it over here
    

Func __Array_FromColumn(ByRef $aArray, $iColumn = 0, $istart = 1)
    Local $aArray1D = ['']
    For $i = $istart To UBound($aArray) - 1
        _ArrayAdd($aArray1D, $aArray[$i][$iColumn])
    Next
    Return $aArray1D
EndFunc   ;==>__Array_FromColumn


 

Share this post


Link to post
Share on other sites

#9 ·  Posted

4 hours ago, kylomas said:

@czardas - yes, before the code was added the request was crystal clear...

Not to me. Extracting a column is not going to solve the crash issue. It could have been a work-around solution to a different problem, in which case further information might have proved useful.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

@Czardas - tongue in cheek.. 

Edited by kylomas
1 person likes this

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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