Jump to content
Sign in to follow this  
Abdulla060

adding elements to 3d arrays

Recommended Posts

Abdulla060

i have a 3d array that is [10][20][6] for now lets assume that its [3][3][3] so it looks something like this 

[[[1,2,3],[1,2,3],[1,2,3]],
 [[1,2,3],[1,2,3],[1,2,3]],
 [[1,2,3],[1,2,3],[1,2,3]]]

i need to add another 1d  array to the position [2][3] ( i hope its clear) so it becomes like this 

[[[1,2,3],[1,2,3],[1,2,3]],
 [[1,2,3],[1,2,3],[1,2,3]],
 [[1,2,3],[1,2,3],[1,2,3],[4,5,6]]]

and i have no idea how :) 

Share this post


Link to post
Share on other sites
TheXman
Posted (edited)

The first thing you would need to do is redim the array because it would no longer fit in a [3][3][3] array.  It would have to be at least [3][4][3].

[
    [
        [1,2,3],
        [1,2,3],
        [1,2,3]
    ],
    [
        [1,2,3],
        [1,2,3],
        [1,2,3]
    ],
    [
        [1,2,3],
        [1,2,3],
        [1,2,3],
        [4,5,6]
    ]
 ]

 

Edited by TheXman
Corrected typo in array structure

Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
TheXman
Posted (edited)
#include <Array.au3>

example()

;==========================================================================
;
;==========================================================================
Func example()

    Local $aArray[3][3][3] = _
        [ _
            [ _
                [1,2,3], _
                [1,2,3], _
                [1,2,3] _
            ], _
            [ _
                [1,2,3], _
                [1,2,3], _
                [1,2,3] _
            ], _
            [ _
                [1,2,3], _
                [1,2,3], _
                [1,2,3] _
            ] _
         ]

    ; Increase the 2nd dimension
    ReDim $aArray[3][4][3]

    ; Add [4,5,6] to [2][3]
    $aArray[2][3][0] = 4
    $aArray[2][3][1] = 5
    $aArray[2][3][2] = 6

    ; Show that [4,5,6] was  successfully added to [2][3]
    Local $aTemp[0]
    _ArrayAdd($aTemp, $aArray[2][3][0])
    _ArrayAdd($aTemp, $aArray[2][3][1])
    _ArrayAdd($aTemp, $aArray[2][3][2])
    _ArrayDisplay($atemp)

EndFunc

 

Edited by TheXman
Fixed a typo

Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
Abdulla060
Posted (edited)

thank you very much for your reply but i decided to just turn the last level of arrays into strings so i ended with a 2d array which is much easier to work with, however now i have a new question how do append data to to each column in a [3][3] array if i use the _arrayadd it will add the data to to the right columns but it will create a new row for each new value

Edited by Abdulla060
changed the question

Share this post


Link to post
Share on other sites
TheXman
Posted (edited)

.

Edited by TheXman
Question was changed so answer was to a different question

Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
TheXman
Posted (edited)

 .

Edited by TheXman
Question was changed so answer was to a different question

Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
Abdulla060
8 minutes ago, TheXman said:
#include <Array.au3>

example1()

Func example1()

    Local $aArray[3][3] = [ [1,1,1], [1,0,0], [1,0,0] ]

    _ArrayDisplay($aArray, "Example1")

EndFunc

 

ok that was a dump question from my end xD sorry about that 

now one last thing and everything is clear for me. how do i append data to a column (without selecting the row basically add data to the first empty cell in a column)

Share this post


Link to post
Share on other sites
TheXman

Maybe it would be easier if I had a better understanding of what you are trying to achieve because your question, as it relates to arrays, does not make much sense to me.  Adding rows is much more common than dynamically adding columns.  It is easy enough to do but I think there's probably a better solution.


Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
Abdulla060
39 minutes ago, TheXman said:

Maybe it would be easier if I had a better understanding of what you are trying to achieve because your question, as it relates to arrays, does not make much sense to me.  Adding rows is much more common than dynamically adding columns.  It is easy enough to do but I think there's probably a better solution.

i have a script that pulls data from a json file and add them to the 3d array from earlier (which is now 2d) im just trying to keep everything in one array rather than defining 10 of them, i want to put the data into each array and make the first element of each array an index of how many things are in each array 

local $array1[3] = [3 ,'a', 'b', 'c']
local $array2[3] = [3 ,'a', 'b', 'c']
Local $array3[3] = [3 ,'a', 'b', 'c']
Local $allarrays[3] = [$array1, $array2, $array3]

what i want is this but using a single 2d array

Share this post


Link to post
Share on other sites
TheXman

Why move the data from JSON into an array?  The JSON data can, most likely, be processed just as easily in its native format as it can be in an array.  It it sounds like it would be much more efficient to process it as JSON since there are already methods/functions to give you the counts of JSON objects and JSON array items.

 


Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
Abdulla060

because i need to edit that data and sort them before i can use it, if not for that then yes using it from the json file would be much more efficient

Share this post


Link to post
Share on other sites
Abdulla060

i give up i'm just going to make 10 arrays :(

Share this post


Link to post
Share on other sites
iamtheky
Posted (edited)

if you have the entire string you can just declare it in a 2D fashion

#include<array.au3>

local $array = [[3 ,'a', 'b', 'c'],[6 ,'a', 'b', 'c','d','e','f'],[4 ,'a', 'b', 'c','d']]

_ArrayDisplay($array)

also, i would add things to it with something like this:

#include<array.au3>

local $array = [[3 ,'a', 'b', 'c'],[6 ,'a', 'b', 'c','d','e','f'],[4 ,'a', 'b', 'c','d']]
_ArrayDisplay($array , 'base')

local $aAdd = [7 ,'a', 'b', 'c','d','e','f','g']

If ubound($aAdd) > ubound($array , 2) Then ReDim $array[ubound($array)][ubound($aAdd)]

_ArrayAdd($array , _ArrayToString($aAdd) , 0 , "|")
_ArrayDisplay($array)

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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
Sign in to follow this  

  • Similar Content

    • autotin
      By autotin
      Hello I am a first time user of AutoIT with little coding experience and I would REALLY really appreciate your help.
      I work in a warehouse where I am responsible for data entry along with a slew of other different tasks such as auditing and managing paperwork. Most of my time is tied up entering info to close receipts of product orders (8-12+ hours for thousands of products). The quantity actually produced by the warehouse is sometimes different from the quantity listed on the reciept (in this case 20). I need to change all the build qty for sublocation "1-WIP" from 20 to the actual quantity 22 and set all other numbers as 0. The form is an iframe coded with jQuery and freezes for 1-2 seconds after every entry and refreshes. As such, it doesn't allow me to use tab and I need to click and type every incorrect field.
      I have attached an image as an example from the webapp, FinaleInventory.
      I'm thinking that I probably need a macro that has a message box entry where I can type the corrected number entry I want. Then it uses image/character recognition (Tesseract?) to find "WIP" sublocation =,   Move the mouse over to the right to "Quantity" relative to location of WIP If quantity number = entry, then move to next "WIP" image (Not quite sure how to make Tesseract "find next") Elseif quantity number ≠ entry then click quantity number of "WIP" and type corrected entry Scroll down Loop until bottom of page I would greatly appreciate any help, ideas or pointers for this project. Thank you!
      -A newbie scripter

    • Pagi
      By Pagi
       
      <a href="index.php=4143b27b41db0a40c499202865c3e24d" class="menuitem " target="\_self"> "Menu Item 1" </a>
      Can you tell me if it´s possible to click this menu button? If yes, how? Cause I have no idea, I think i should use _IETagNameGetCollection
    • mar3011
      By mar3011
      hello, I want to set in the inputbox field random key from the keyboard to which the function will be assigned, for example F4 function start notepad ALT + A function start notepad for one function. Thank you for any help.  
    • JuanFelipe
      By JuanFelipe
      Cambiar a español Hello friends, I need help with a problem I have, I want to know if there is any way to update a GUI already running, that is I have a GUI of a certain size and with a button I would like to enlarge it:
      example: $ form1 = GUICreate ("", 200,100,0,0)   When you press the button, the gui increases its size, and actuates the new size.
    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
×