Julia: 2d array assignment












0















I'm trying to do the assignment in the 2d array with the nested loop. I'm trying to access the elements of the array as follows. But I get a mistake. I've searched, but I didn't get results. How can I assign Julia in the 2d array?



for x in 1:total
for y in 1:W
@show (x, y)
if agirliklar[x] <= y

V[x][y] = getMax(V[x-1][y], degerler[x] + V[x-1][y - agirliklar[x]])


else
print("sa")
V[x][y] = V[x-1][y]
end
end
end


BoundsError: attempt to access 7×6 Array{Int64,2} at index [0]



My code



Error










share|improve this question























  • It would be useful to see (example) definitions of total, W, agirliklar, degerler, and V. But maybe it's just that x-1 is one-off?

    – phg
    Dec 30 '18 at 10:06
















0















I'm trying to do the assignment in the 2d array with the nested loop. I'm trying to access the elements of the array as follows. But I get a mistake. I've searched, but I didn't get results. How can I assign Julia in the 2d array?



for x in 1:total
for y in 1:W
@show (x, y)
if agirliklar[x] <= y

V[x][y] = getMax(V[x-1][y], degerler[x] + V[x-1][y - agirliklar[x]])


else
print("sa")
V[x][y] = V[x-1][y]
end
end
end


BoundsError: attempt to access 7×6 Array{Int64,2} at index [0]



My code



Error










share|improve this question























  • It would be useful to see (example) definitions of total, W, agirliklar, degerler, and V. But maybe it's just that x-1 is one-off?

    – phg
    Dec 30 '18 at 10:06














0












0








0








I'm trying to do the assignment in the 2d array with the nested loop. I'm trying to access the elements of the array as follows. But I get a mistake. I've searched, but I didn't get results. How can I assign Julia in the 2d array?



for x in 1:total
for y in 1:W
@show (x, y)
if agirliklar[x] <= y

V[x][y] = getMax(V[x-1][y], degerler[x] + V[x-1][y - agirliklar[x]])


else
print("sa")
V[x][y] = V[x-1][y]
end
end
end


BoundsError: attempt to access 7×6 Array{Int64,2} at index [0]



My code



Error










share|improve this question














I'm trying to do the assignment in the 2d array with the nested loop. I'm trying to access the elements of the array as follows. But I get a mistake. I've searched, but I didn't get results. How can I assign Julia in the 2d array?



for x in 1:total
for y in 1:W
@show (x, y)
if agirliklar[x] <= y

V[x][y] = getMax(V[x-1][y], degerler[x] + V[x-1][y - agirliklar[x]])


else
print("sa")
V[x][y] = V[x-1][y]
end
end
end


BoundsError: attempt to access 7×6 Array{Int64,2} at index [0]



My code



Error







arrays multidimensional-array julia-lang






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 30 '18 at 8:43









Mehmet AcarMehmet Acar

1




1













  • It would be useful to see (example) definitions of total, W, agirliklar, degerler, and V. But maybe it's just that x-1 is one-off?

    – phg
    Dec 30 '18 at 10:06



















  • It would be useful to see (example) definitions of total, W, agirliklar, degerler, and V. But maybe it's just that x-1 is one-off?

    – phg
    Dec 30 '18 at 10:06

















It would be useful to see (example) definitions of total, W, agirliklar, degerler, and V. But maybe it's just that x-1 is one-off?

– phg
Dec 30 '18 at 10:06





It would be useful to see (example) definitions of total, W, agirliklar, degerler, and V. But maybe it's just that x-1 is one-off?

– phg
Dec 30 '18 at 10:06












2 Answers
2






active

oldest

votes


















4














In Julia arrays are 1-based not 0-based.



You try to access V[x-1] where x can take value of 1.



Site note: always provide a minimum working example (MWE) rather than just dumping a part of your production code.






share|improve this answer































    3














    (At least) two things are wrong here:




    1. As @PrzemyslawSzufel says, ordinary Julia arrays are 1-indexed, so you cannot access them at index zero. Though it is possible to get special arrays that are 0-indexed.

    2. If V is a 2D array, as you are saying, you cannot access it like this: V[x][y]. Instead you access them like this: V[x, y]. You can read more about this here: https://docs.julialang.org/en/v1/manual/arrays/#man-array-indexing-1






    share|improve this answer
























    • Thanks it works

      – Mehmet Acar
      Jan 1 at 6:58











    • If one of the answers solves your problem, please consider marking one of them as the accepted answer.

      – DNF
      Jan 1 at 10:44











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53976269%2fjulia-2d-array-assignment%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    In Julia arrays are 1-based not 0-based.



    You try to access V[x-1] where x can take value of 1.



    Site note: always provide a minimum working example (MWE) rather than just dumping a part of your production code.






    share|improve this answer




























      4














      In Julia arrays are 1-based not 0-based.



      You try to access V[x-1] where x can take value of 1.



      Site note: always provide a minimum working example (MWE) rather than just dumping a part of your production code.






      share|improve this answer


























        4












        4








        4







        In Julia arrays are 1-based not 0-based.



        You try to access V[x-1] where x can take value of 1.



        Site note: always provide a minimum working example (MWE) rather than just dumping a part of your production code.






        share|improve this answer













        In Julia arrays are 1-based not 0-based.



        You try to access V[x-1] where x can take value of 1.



        Site note: always provide a minimum working example (MWE) rather than just dumping a part of your production code.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 30 '18 at 11:15









        Przemyslaw SzufelPrzemyslaw Szufel

        1,719111




        1,719111

























            3














            (At least) two things are wrong here:




            1. As @PrzemyslawSzufel says, ordinary Julia arrays are 1-indexed, so you cannot access them at index zero. Though it is possible to get special arrays that are 0-indexed.

            2. If V is a 2D array, as you are saying, you cannot access it like this: V[x][y]. Instead you access them like this: V[x, y]. You can read more about this here: https://docs.julialang.org/en/v1/manual/arrays/#man-array-indexing-1






            share|improve this answer
























            • Thanks it works

              – Mehmet Acar
              Jan 1 at 6:58











            • If one of the answers solves your problem, please consider marking one of them as the accepted answer.

              – DNF
              Jan 1 at 10:44
















            3














            (At least) two things are wrong here:




            1. As @PrzemyslawSzufel says, ordinary Julia arrays are 1-indexed, so you cannot access them at index zero. Though it is possible to get special arrays that are 0-indexed.

            2. If V is a 2D array, as you are saying, you cannot access it like this: V[x][y]. Instead you access them like this: V[x, y]. You can read more about this here: https://docs.julialang.org/en/v1/manual/arrays/#man-array-indexing-1






            share|improve this answer
























            • Thanks it works

              – Mehmet Acar
              Jan 1 at 6:58











            • If one of the answers solves your problem, please consider marking one of them as the accepted answer.

              – DNF
              Jan 1 at 10:44














            3












            3








            3







            (At least) two things are wrong here:




            1. As @PrzemyslawSzufel says, ordinary Julia arrays are 1-indexed, so you cannot access them at index zero. Though it is possible to get special arrays that are 0-indexed.

            2. If V is a 2D array, as you are saying, you cannot access it like this: V[x][y]. Instead you access them like this: V[x, y]. You can read more about this here: https://docs.julialang.org/en/v1/manual/arrays/#man-array-indexing-1






            share|improve this answer













            (At least) two things are wrong here:




            1. As @PrzemyslawSzufel says, ordinary Julia arrays are 1-indexed, so you cannot access them at index zero. Though it is possible to get special arrays that are 0-indexed.

            2. If V is a 2D array, as you are saying, you cannot access it like this: V[x][y]. Instead you access them like this: V[x, y]. You can read more about this here: https://docs.julialang.org/en/v1/manual/arrays/#man-array-indexing-1







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 31 '18 at 10:03









            DNFDNF

            2,430619




            2,430619













            • Thanks it works

              – Mehmet Acar
              Jan 1 at 6:58











            • If one of the answers solves your problem, please consider marking one of them as the accepted answer.

              – DNF
              Jan 1 at 10:44



















            • Thanks it works

              – Mehmet Acar
              Jan 1 at 6:58











            • If one of the answers solves your problem, please consider marking one of them as the accepted answer.

              – DNF
              Jan 1 at 10:44

















            Thanks it works

            – Mehmet Acar
            Jan 1 at 6:58





            Thanks it works

            – Mehmet Acar
            Jan 1 at 6:58













            If one of the answers solves your problem, please consider marking one of them as the accepted answer.

            – DNF
            Jan 1 at 10:44





            If one of the answers solves your problem, please consider marking one of them as the accepted answer.

            – DNF
            Jan 1 at 10:44


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53976269%2fjulia-2d-array-assignment%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas