{
  "id": 323849,
  "title": "Stacking numpy array delima",
  "url": "/competitions/smartphone-decimeter-2022/discussion/323849",
  "author_name": "",
  "post_date": "2022-05-08T19:51:35.517461200Z",
  "votes": 2,
  "comment_count": 6,
  "views": 0,
  "content": "<p>I want to perform this operation in numpy:<br>\nA= [ [1,2],[3,4] ] <br>\nB= [ [1,2],[3,4],[5,6] ]<br>\nZ &lt;- [ A , B ] <br>\ni.e. <br>\nZ = [<br>\n  [ [1,2],[3,4] ]<strong>,</strong> <br>\n  [ [1,2],[3,4],[5,6] ]<br>\n ]</p>\n<p>And then I want to keep adding different size arrays like A,B to Z <br>\nZ = [<br>\n  [ [1,2],[3,4] ],<br>\n  [ [1,2],[3,4],[5,6] ],<br>\n  [ [1,2],[3,4],[5,6] ],[2,3]<br>\n  [ [1,2]]<br>\n ]</p>\n<p>How can I achieve this?</p>\n<p>UPDATE: </p>\n<ul>\n<li>There is no way in numpy to solve this issue.</li>\n<li>We have to either mask it or pad the data.</li>\n<li>I am going to mask data with Zero(to make it equal size array). Models have a parameter like mask_zero=True to ignore that padded data. Thus solving the issue of unequal size of input data.</li>\n</ul>",
  "messages": [
    {
      "id": "1781671",
      "postDate": "05/08/2022 19:51:35",
      "content": "<p>I want to perform this operation in numpy:<br>\nA= [ [1,2],[3,4] ] <br>\nB= [ [1,2],[3,4],[5,6] ]<br>\nZ &lt;- [ A , B ] <br>\ni.e. <br>\nZ = [<br>\n  [ [1,2],[3,4] ]<strong>,</strong> <br>\n  [ [1,2],[3,4],[5,6] ]<br>\n ]</p>\n<p>And then I want to keep adding different size arrays like A,B to Z <br>\nZ = [<br>\n  [ [1,2],[3,4] ],<br>\n  [ [1,2],[3,4],[5,6] ],<br>\n  [ [1,2],[3,4],[5,6] ],[2,3]<br>\n  [ [1,2]]<br>\n ]</p>\n<p>How can I achieve this?</p>\n<p>UPDATE: </p>\n<ul>\n<li>There is no way in numpy to solve this issue.</li>\n<li>We have to either mask it or pad the data.</li>\n<li>I am going to mask data with Zero(to make it equal size array). Models have a parameter like mask_zero=True to ignore that padded data. Thus solving the issue of unequal size of input data.</li>\n</ul>",
      "rawMarkdown": "I want to perform this operation in numpy:\nA= [ [1,2],[3,4] ] \nB= [ [1,2],[3,4],[5,6] ]\nZ <- [ A , B ] \ni.e. \nZ = [\n  [ [1,2],[3,4] ]**,** \n  [ [1,2],[3,4],[5,6] ]\n ]\n\nAnd then I want to keep adding different size arrays like A,B to Z \nZ = [\n  [ [1,2],[3,4] ],\n  [ [1,2],[3,4],[5,6] ],\n  [ [1,2],[3,4],[5,6] ],[2,3]\n  [ [1,2]]\n ]\n\nHow can I achieve this?\n\nUPDATE: \n- There is no way in numpy to solve this issue.\n- We have to either mask it or pad the data.\n- I am going to mask data with Zero(to make it equal size array). Models have a parameter like mask_zero=True to ignore that padded data. Thus solving the issue of unequal size of input data.",
      "votes": null
    },
    {
      "id": "1781695",
      "postDate": "05/08/2022 20:41:40",
      "content": "<p>numpy doesn't like you to make jagged \"normal\" arrays (elements of different sizes); you can do this as a numpy array of numpy arrays like this:</p>\n<p>a = np.array([ [1,2],[3,4] ])<br>\nb = np.array([ [1,2],[3,4],[5,6] ])<br>\nz = np.array((a,b), dtype=object)</p>\n<p>but I don't think that's what you want?</p>\n<p>Maybe there's a way I don't know about though</p>",
      "rawMarkdown": "numpy doesn't like you to make jagged \"normal\" arrays (elements of different sizes); you can do this as a numpy array of numpy arrays like this:\n\na = np.array([ [1,2],[3,4] ])\nb = np.array([ [1,2],[3,4],[5,6] ])\nz = np.array((a,b), dtype=object)\n\nbut I don't think that's what you want?\n\nMaybe there's a way I don't know about though",
      "votes": null
    },
    {
      "id": "1781987",
      "postDate": "05/09/2022 06:08:57",
      "content": "<p>Actually, I was able to create a jagged numpy array in this fashion:<br>\nA = np.array(  <br>\n    [  </p>\n<pre><code>    [[1, 1], [3, 3], [5, 5], [9, 9]],  \n\n    [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]],  \n\n    [[1, 1], [3, 3], [9, 9]],  \n\n    [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]],  \n\n    [9, 9]],  \n\n    [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]]  \n\n]  \n</code></pre>\n<p>)</p>\n<p>So I thought maybe there is a way to combine/stack individual such arrays(which I am getting from the data) in numpy!<br>\nBut having a hard time figuring that out.</p>",
      "rawMarkdown": "Actually, I was able to create a jagged numpy array in this fashion:\nA = np.array(  \n    [  \n\n        [[1, 1], [3, 3], [5, 5], [9, 9]],  \n\n        [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]],  \n\n        [[1, 1], [3, 3], [9, 9]],  \n\n        [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]],  \n\n        [9, 9]],  \n\n        [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]]  \n\n    ]  \n\n)\n\nSo I thought maybe there is a way to combine/stack individual such arrays(which I am getting from the data) in numpy!\nBut having a hard time figuring that out.",
      "votes": null
    },
    {
      "id": "1782263",
      "postDate": "05/09/2022 11:49:02",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/jimitshah777\" target=\"_blank\">@jimitshah777</a>, did you try with np.vstack() function, this might help</p>",
      "rawMarkdown": "Hi @jimitshah777, did you try with np.vstack() function, this might help",
      "votes": null
    },
    {
      "id": "1782363",
      "postDate": "05/09/2022 14:22:46",
      "content": "<p>Yes I tried that too, looks like I will have to pad the data with null/None. The operation which I want to perform is not supported in numpy!</p>",
      "rawMarkdown": "Yes I tried that too, looks like I will have to pad the data with null/None. The operation which I want to perform is not supported in numpy!",
      "votes": null
    },
    {
      "id": "1782391",
      "postDate": "05/09/2022 14:39:24",
      "content": "<p>Please post here, if you find any solution. I am also eager to know, how to do it. Thanks.</p>",
      "rawMarkdown": "Please post here, if you find any solution. I am also eager to know, how to do it. Thanks.",
      "votes": null
    },
    {
      "id": "1782558",
      "postDate": "05/09/2022 17:09:35",
      "content": "<p>I am going to mask data with Zero(to make it equal size array). Models have a parameter like mask_zero=True to ignore that padded data. Thus solving the issue of unequal size of input data.</p>",
      "rawMarkdown": "I am going to mask data with Zero(to make it equal size array). Models have a parameter like mask_zero=True to ignore that padded data. Thus solving the issue of unequal size of input data.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1781695,
      "author_name": "chris62",
      "author_url": "",
      "post_date": "05/08/2022 20:41:40",
      "content": "<p>numpy doesn't like you to make jagged \"normal\" arrays (elements of different sizes); you can do this as a numpy array of numpy arrays like this:</p>\n<p>a = np.array([ [1,2],[3,4] ])<br>\nb = np.array([ [1,2],[3,4],[5,6] ])<br>\nz = np.array((a,b), dtype=object)</p>\n<p>but I don't think that's what you want?</p>\n<p>Maybe there's a way I don't know about though</p>",
      "votes": null,
      "replies": [
        {
          "id": 1781987,
          "author_name": "jimitshah777",
          "author_url": "",
          "post_date": "05/09/2022 06:08:57",
          "content": "<p>Actually, I was able to create a jagged numpy array in this fashion:<br>\nA = np.array(  <br>\n    [  </p>\n<pre><code>    [[1, 1], [3, 3], [5, 5], [9, 9]],  \n\n    [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]],  \n\n    [[1, 1], [3, 3], [9, 9]],  \n\n    [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]],  \n\n    [9, 9]],  \n\n    [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]]  \n\n]  \n</code></pre>\n<p>)</p>\n<p>So I thought maybe there is a way to combine/stack individual such arrays(which I am getting from the data) in numpy!<br>\nBut having a hard time figuring that out.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1782263,
          "author_name": "balabaskar",
          "author_url": "",
          "post_date": "05/09/2022 11:49:02",
          "content": "<p>Hi <a href=\"https://www.kaggle.com/jimitshah777\" target=\"_blank\">@jimitshah777</a>, did you try with np.vstack() function, this might help</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1782363,
          "author_name": "jimitshah777",
          "author_url": "",
          "post_date": "05/09/2022 14:22:46",
          "content": "<p>Yes I tried that too, looks like I will have to pad the data with null/None. The operation which I want to perform is not supported in numpy!</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1782391,
          "author_name": "balabaskar",
          "author_url": "",
          "post_date": "05/09/2022 14:39:24",
          "content": "<p>Please post here, if you find any solution. I am also eager to know, how to do it. Thanks.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1782558,
          "author_name": "jimitshah777",
          "author_url": "",
          "post_date": "05/09/2022 17:09:35",
          "content": "<p>I am going to mask data with Zero(to make it equal size array). Models have a parameter like mask_zero=True to ignore that padded data. Thus solving the issue of unequal size of input data.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1781671": "I want to perform this operation in numpy:\nA= [ [1,2],[3,4] ] \nB= [ [1,2],[3,4],[5,6] ]\nZ <- [ A , B ] \ni.e. \nZ = [\n  [ [1,2],[3,4] ]**,** \n  [ [1,2],[3,4],[5,6] ]\n ]\n\nAnd then I want to keep adding different size arrays like A,B to Z \nZ = [\n  [ [1,2],[3,4] ],\n  [ [1,2],[3,4],[5,6] ],\n  [ [1,2],[3,4],[5,6] ],[2,3]\n  [ [1,2]]\n ]\n\nHow can I achieve this?\n\nUPDATE: \n- There is no way in numpy to solve this issue.\n- We have to either mask it or pad the data.\n- I am going to mask data with Zero(to make it equal size array). Models have a parameter like mask_zero=True to ignore that padded data. Thus solving the issue of unequal size of input data.",
    "1781695": "numpy doesn't like you to make jagged \"normal\" arrays (elements of different sizes); you can do this as a numpy array of numpy arrays like this:\n\na = np.array([ [1,2],[3,4] ])\nb = np.array([ [1,2],[3,4],[5,6] ])\nz = np.array((a,b), dtype=object)\n\nbut I don't think that's what you want?\n\nMaybe there's a way I don't know about though",
    "1781987": "Actually, I was able to create a jagged numpy array in this fashion:\nA = np.array(  \n    [  \n\n        [[1, 1], [3, 3], [5, 5], [9, 9]],  \n\n        [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]],  \n\n        [[1, 1], [3, 3], [9, 9]],  \n\n        [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]],  \n\n        [9, 9]],  \n\n        [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]]  \n\n    ]  \n\n)\n\nSo I thought maybe there is a way to combine/stack individual such arrays(which I am getting from the data) in numpy!\nBut having a hard time figuring that out.",
    "1782263": "Hi @jimitshah777, did you try with np.vstack() function, this might help",
    "1782363": "Yes I tried that too, looks like I will have to pad the data with null/None. The operation which I want to perform is not supported in numpy!",
    "1782391": "Please post here, if you find any solution. I am also eager to know, how to do it. Thanks.",
    "1782558": "I am going to mask data with Zero(to make it equal size array). Models have a parameter like mask_zero=True to ignore that padded data. Thus solving the issue of unequal size of input data."
  },
  "source": "meta"
}