Handle 4 dimensional array python










0















I want to create a list of 10 matrix (32,32,3) that will contain a sum of values from my RGB images.



So I used matrixSum = np.zeros((10,32,32,3),np.uint64)

And I thought to access it using matrixSum[indiceClass][ligne][col][rgb]

But I keep having an error telling me that matrixSum[indiceClass] is only size 1
enter image description here

So I changed my code to matrixSum[indiceClass][0][ligne][col][rgb] and I do not have this error anymore but it brings me troubles later.



Am I doing something wrong? It don't understand why I would have an array of size 1 in the middle instead of 32. Or is it logical?

Here is the full code of the function : (indiceclasse will only be between 0 and 9)



def createMatrixSum(data, nbImagesParClasse):
matricesSum = np.zeros((10,32,32,3),np.uint64)
indiceClasse = 0
for i in range(0,80):
indiceClasse = data["y"][i]
indiceClasse -= 1;
nbImagesParClasse[indiceClasse] += 1
for ligne in range(32):
for col in range(32):
for rgb in range(3):
matricesSum[indiceClasse][ligne][col][rgb] += data["X"][ligne,col,rgb,i]
return matricesSum, nbImagesParClasse


Edit : here is the len and shape of my data/matrix before the error.
enter image description here

I don't see anything wrong.










share|improve this question
























  • Left hand side seems ok, can you check len/shape of data.

    – Seljuk Gülcan
    Nov 15 '18 at 0:42











  • Added information on len and shape. But what I find strange is that matrixSum[indiceClass][0][ligne][col][rgb] is working even though it shouldn't.

    – FloLp
    Nov 15 '18 at 8:22
















0















I want to create a list of 10 matrix (32,32,3) that will contain a sum of values from my RGB images.



So I used matrixSum = np.zeros((10,32,32,3),np.uint64)

And I thought to access it using matrixSum[indiceClass][ligne][col][rgb]

But I keep having an error telling me that matrixSum[indiceClass] is only size 1
enter image description here

So I changed my code to matrixSum[indiceClass][0][ligne][col][rgb] and I do not have this error anymore but it brings me troubles later.



Am I doing something wrong? It don't understand why I would have an array of size 1 in the middle instead of 32. Or is it logical?

Here is the full code of the function : (indiceclasse will only be between 0 and 9)



def createMatrixSum(data, nbImagesParClasse):
matricesSum = np.zeros((10,32,32,3),np.uint64)
indiceClasse = 0
for i in range(0,80):
indiceClasse = data["y"][i]
indiceClasse -= 1;
nbImagesParClasse[indiceClasse] += 1
for ligne in range(32):
for col in range(32):
for rgb in range(3):
matricesSum[indiceClasse][ligne][col][rgb] += data["X"][ligne,col,rgb,i]
return matricesSum, nbImagesParClasse


Edit : here is the len and shape of my data/matrix before the error.
enter image description here

I don't see anything wrong.










share|improve this question
























  • Left hand side seems ok, can you check len/shape of data.

    – Seljuk Gülcan
    Nov 15 '18 at 0:42











  • Added information on len and shape. But what I find strange is that matrixSum[indiceClass][0][ligne][col][rgb] is working even though it shouldn't.

    – FloLp
    Nov 15 '18 at 8:22














0












0








0








I want to create a list of 10 matrix (32,32,3) that will contain a sum of values from my RGB images.



So I used matrixSum = np.zeros((10,32,32,3),np.uint64)

And I thought to access it using matrixSum[indiceClass][ligne][col][rgb]

But I keep having an error telling me that matrixSum[indiceClass] is only size 1
enter image description here

So I changed my code to matrixSum[indiceClass][0][ligne][col][rgb] and I do not have this error anymore but it brings me troubles later.



Am I doing something wrong? It don't understand why I would have an array of size 1 in the middle instead of 32. Or is it logical?

Here is the full code of the function : (indiceclasse will only be between 0 and 9)



def createMatrixSum(data, nbImagesParClasse):
matricesSum = np.zeros((10,32,32,3),np.uint64)
indiceClasse = 0
for i in range(0,80):
indiceClasse = data["y"][i]
indiceClasse -= 1;
nbImagesParClasse[indiceClasse] += 1
for ligne in range(32):
for col in range(32):
for rgb in range(3):
matricesSum[indiceClasse][ligne][col][rgb] += data["X"][ligne,col,rgb,i]
return matricesSum, nbImagesParClasse


Edit : here is the len and shape of my data/matrix before the error.
enter image description here

I don't see anything wrong.










share|improve this question
















I want to create a list of 10 matrix (32,32,3) that will contain a sum of values from my RGB images.



So I used matrixSum = np.zeros((10,32,32,3),np.uint64)

And I thought to access it using matrixSum[indiceClass][ligne][col][rgb]

But I keep having an error telling me that matrixSum[indiceClass] is only size 1
enter image description here

So I changed my code to matrixSum[indiceClass][0][ligne][col][rgb] and I do not have this error anymore but it brings me troubles later.



Am I doing something wrong? It don't understand why I would have an array of size 1 in the middle instead of 32. Or is it logical?

Here is the full code of the function : (indiceclasse will only be between 0 and 9)



def createMatrixSum(data, nbImagesParClasse):
matricesSum = np.zeros((10,32,32,3),np.uint64)
indiceClasse = 0
for i in range(0,80):
indiceClasse = data["y"][i]
indiceClasse -= 1;
nbImagesParClasse[indiceClasse] += 1
for ligne in range(32):
for col in range(32):
for rgb in range(3):
matricesSum[indiceClasse][ligne][col][rgb] += data["X"][ligne,col,rgb,i]
return matricesSum, nbImagesParClasse


Edit : here is the len and shape of my data/matrix before the error.
enter image description here

I don't see anything wrong.







python matrix size rgb






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 15:30







FloLp

















asked Nov 15 '18 at 0:19









FloLpFloLp

235




235












  • Left hand side seems ok, can you check len/shape of data.

    – Seljuk Gülcan
    Nov 15 '18 at 0:42











  • Added information on len and shape. But what I find strange is that matrixSum[indiceClass][0][ligne][col][rgb] is working even though it shouldn't.

    – FloLp
    Nov 15 '18 at 8:22


















  • Left hand side seems ok, can you check len/shape of data.

    – Seljuk Gülcan
    Nov 15 '18 at 0:42











  • Added information on len and shape. But what I find strange is that matrixSum[indiceClass][0][ligne][col][rgb] is working even though it shouldn't.

    – FloLp
    Nov 15 '18 at 8:22

















Left hand side seems ok, can you check len/shape of data.

– Seljuk Gülcan
Nov 15 '18 at 0:42





Left hand side seems ok, can you check len/shape of data.

– Seljuk Gülcan
Nov 15 '18 at 0:42













Added information on len and shape. But what I find strange is that matrixSum[indiceClass][0][ligne][col][rgb] is working even though it shouldn't.

– FloLp
Nov 15 '18 at 8:22






Added information on len and shape. But what I find strange is that matrixSum[indiceClass][0][ligne][col][rgb] is working even though it shouldn't.

– FloLp
Nov 15 '18 at 8:22













1 Answer
1






active

oldest

votes


















0














Well, turns out that the "indiceClass" I tried to obtain was not an integer as I thought but a list of size 1.
So using it as an index added another list into my matrix which explain why I got that list into the middle. Should have checked that beforehand.






share|improve this answer






















    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%2f53310718%2fhandle-4-dimensional-array-python%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Well, turns out that the "indiceClass" I tried to obtain was not an integer as I thought but a list of size 1.
    So using it as an index added another list into my matrix which explain why I got that list into the middle. Should have checked that beforehand.






    share|improve this answer



























      0














      Well, turns out that the "indiceClass" I tried to obtain was not an integer as I thought but a list of size 1.
      So using it as an index added another list into my matrix which explain why I got that list into the middle. Should have checked that beforehand.






      share|improve this answer

























        0












        0








        0







        Well, turns out that the "indiceClass" I tried to obtain was not an integer as I thought but a list of size 1.
        So using it as an index added another list into my matrix which explain why I got that list into the middle. Should have checked that beforehand.






        share|improve this answer













        Well, turns out that the "indiceClass" I tried to obtain was not an integer as I thought but a list of size 1.
        So using it as an index added another list into my matrix which explain why I got that list into the middle. Should have checked that beforehand.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 20:50









        FloLpFloLp

        235




        235





























            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%2f53310718%2fhandle-4-dimensional-array-python%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







            這個網誌中的熱門文章

            Barbados

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3