{
  "id": 21452,
  "title": "how to remove square brackets in submission",
  "url": "/competitions/expedia-hotel-recommendations/discussion/21452",
  "author_name": "",
  "post_date": "2016-06-06T01:06:15.680Z",
  "votes": null,
  "comment_count": 5,
  "views": 564,
  "content": "<p>Hi,</p>\n\n<p>I am trying to submit a text file.  However, my submission looks like:</p>\n\n<p>0, [91 48 41 64 42]\n1, [91 41 48 83 90]</p>\n\n<p>I don't want the square brackets, but I think they are there because my numpy matrix looks like below.  How do I remove these brackets from my numpy matrix so I can make a submission file without brackets?</p>\n\n<p>array([['0', '[91 48 41 64 42]'],\n       ['1', '[91 48 41 64 42]'],\n       ['2', '[91 41 48 83 90]'],\n       ..., \n       ['2528240', '[91 48 41 5 64]'],\n       ['2528241', '[91 48 41 5 64]'],\n       ['2528242', '[91 48 41 64 42]']], \n      dtype='|S21')</p>\n\n<p>Any help would be appreciated.</p>\n\n<p>Thank you,\nMike</p>",
  "messages": [
    {
      "id": "122635",
      "postDate": "06/06/2016 01:06:15",
      "content": "<p>Hi,</p>\n\n<p>I am trying to submit a text file.  However, my submission looks like:</p>\n\n<p>0, [91 48 41 64 42]\n1, [91 41 48 83 90]</p>\n\n<p>I don't want the square brackets, but I think they are there because my numpy matrix looks like below.  How do I remove these brackets from my numpy matrix so I can make a submission file without brackets?</p>\n\n<p>array([['0', '[91 48 41 64 42]'],\n       ['1', '[91 48 41 64 42]'],\n       ['2', '[91 41 48 83 90]'],\n       ..., \n       ['2528240', '[91 48 41 5 64]'],\n       ['2528241', '[91 48 41 5 64]'],\n       ['2528242', '[91 48 41 64 42]']], \n      dtype='|S21')</p>\n\n<p>Any help would be appreciated.</p>\n\n<p>Thank you,\nMike</p>",
      "rawMarkdown": "Hi,\r\n\r\nI am trying to submit a text file.  However, my submission looks like:\r\n\r\n0, [91 48 41 64 42]\r\n1, [91 41 48 83 90]\r\n\r\nI don't want the square brackets, but I think they are there because my numpy matrix looks like below.  How do I remove these brackets from my numpy matrix so I can make a submission file without brackets?\r\n\r\narray([['0', '[91 48 41 64 42]'],\r\n       ['1', '[91 48 41 64 42]'],\r\n       ['2', '[91 41 48 83 90]'],\r\n       ..., \r\n       ['2528240', '[91 48 41 5 64]'],\r\n       ['2528241', '[91 48 41 5 64]'],\r\n       ['2528242', '[91 48 41 64 42]']], \r\n      dtype='|S21')\r\n\r\nAny help would be appreciated.\r\n\r\nThank you,\r\nMike",
      "votes": null
    },
    {
      "id": "122759",
      "postDate": "06/07/2016 00:32:24",
      "content": "<p>Problem was solved.</p>",
      "rawMarkdown": "Problem was solved.",
      "votes": null
    },
    {
      "id": "122865",
      "postDate": "06/07/2016 21:49:10",
      "content": "<p>and the solution? ;-)</p>",
      "rawMarkdown": "and the solution? ;-)",
      "votes": null
    },
    {
      "id": "122866",
      "postDate": "06/07/2016 21:54:01",
      "content": "<p>Alex,</p>\n\n<p>I used pandas instead of numpy to take off the square brackets.  I had to use numpy to get the top 5 hotel clusters, but numpy didn't seem to offer a way to take off the brackets.</p>\n\n<p>here's the method that helped clip the brackets:</p>\n\n<p>panda_submit['hotel_cluster'] = panda_submit['hotel_cluster'].map(lambda x: x.lstrip('[').rstrip(']'))</p>",
      "rawMarkdown": "Alex,\r\n\r\nI used pandas instead of numpy to take off the square brackets.  I had to use numpy to get the top 5 hotel clusters, but numpy didn't seem to offer a way to take off the brackets.\r\n\r\nhere's the method that helped clip the brackets:\r\n\r\npanda_submit['hotel_cluster'] = panda_submit['hotel_cluster'].map(lambda x: x.lstrip('[').rstrip(']'))",
      "votes": null
    },
    {
      "id": "122873",
      "postDate": "06/07/2016 23:07:01",
      "content": "<p>convert numpy array to list with .tolist() method in numpy. Then you can use list comperhension like :</p>\n\n<pre><code>submission = submission.tolist()\nsubmission = [str(x[0])+&quot;,&quot;+str(x[1][0])+&quot; &quot;+str(x[1][1])+&quot; &quot;+str(x[1][2])+&quot; &quot;+str(x[1][3])+&quot; &quot;+str(x[1][4]) for x in submission]\n</code></pre>",
      "rawMarkdown": "convert numpy array to list with .tolist() method in numpy. Then you can use list comperhension like :\r\n\r\n    submission = submission.tolist()\r\n    submission = [str(x[0])+\",\"+str(x[1][0])+\" \"+str(x[1][1])+\" \"+str(x[1][2])+\" \"+str(x[1][3])+\" \"+str(x[1][4]) for x in submission]",
      "votes": null
    },
    {
      "id": "122874",
      "postDate": "06/07/2016 23:16:21",
      "content": "<p>Shahnawaz,</p>\n\n<p>Thank you.  I tried to convert from numpy to a list at first, but did not know about the list comprehension you demonstrated.  That's a simpler and better way to do it!</p>",
      "rawMarkdown": "Shahnawaz,\r\n\r\nThank you.  I tried to convert from numpy to a list at first, but did not know about the list comprehension you demonstrated.  That's a simpler and better way to do it!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 122759,
      "author_name": "mikebak",
      "author_url": "",
      "post_date": "06/07/2016 00:32:24",
      "content": "<p>Problem was solved.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 122865,
      "author_name": "amonras",
      "author_url": "",
      "post_date": "06/07/2016 21:49:10",
      "content": "<p>and the solution? ;-)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 122866,
      "author_name": "mikebak",
      "author_url": "",
      "post_date": "06/07/2016 21:54:01",
      "content": "<p>Alex,</p>\n\n<p>I used pandas instead of numpy to take off the square brackets.  I had to use numpy to get the top 5 hotel clusters, but numpy didn't seem to offer a way to take off the brackets.</p>\n\n<p>here's the method that helped clip the brackets:</p>\n\n<p>panda_submit['hotel_cluster'] = panda_submit['hotel_cluster'].map(lambda x: x.lstrip('[').rstrip(']'))</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 122873,
      "author_name": "shahnawazakhtar",
      "author_url": "",
      "post_date": "06/07/2016 23:07:01",
      "content": "<p>convert numpy array to list with .tolist() method in numpy. Then you can use list comperhension like :</p>\n\n<pre><code>submission = submission.tolist()\nsubmission = [str(x[0])+&quot;,&quot;+str(x[1][0])+&quot; &quot;+str(x[1][1])+&quot; &quot;+str(x[1][2])+&quot; &quot;+str(x[1][3])+&quot; &quot;+str(x[1][4]) for x in submission]\n</code></pre>",
      "votes": null,
      "replies": []
    },
    {
      "id": 122874,
      "author_name": "mikebak",
      "author_url": "",
      "post_date": "06/07/2016 23:16:21",
      "content": "<p>Shahnawaz,</p>\n\n<p>Thank you.  I tried to convert from numpy to a list at first, but did not know about the list comprehension you demonstrated.  That's a simpler and better way to do it!</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "122635": "Hi,\r\n\r\nI am trying to submit a text file.  However, my submission looks like:\r\n\r\n0, [91 48 41 64 42]\r\n1, [91 41 48 83 90]\r\n\r\nI don't want the square brackets, but I think they are there because my numpy matrix looks like below.  How do I remove these brackets from my numpy matrix so I can make a submission file without brackets?\r\n\r\narray([['0', '[91 48 41 64 42]'],\r\n       ['1', '[91 48 41 64 42]'],\r\n       ['2', '[91 41 48 83 90]'],\r\n       ..., \r\n       ['2528240', '[91 48 41 5 64]'],\r\n       ['2528241', '[91 48 41 5 64]'],\r\n       ['2528242', '[91 48 41 64 42]']], \r\n      dtype='|S21')\r\n\r\nAny help would be appreciated.\r\n\r\nThank you,\r\nMike",
    "122759": "Problem was solved.",
    "122865": "and the solution? ;-)",
    "122866": "Alex,\r\n\r\nI used pandas instead of numpy to take off the square brackets.  I had to use numpy to get the top 5 hotel clusters, but numpy didn't seem to offer a way to take off the brackets.\r\n\r\nhere's the method that helped clip the brackets:\r\n\r\npanda_submit['hotel_cluster'] = panda_submit['hotel_cluster'].map(lambda x: x.lstrip('[').rstrip(']'))",
    "122873": "convert numpy array to list with .tolist() method in numpy. Then you can use list comperhension like :\r\n\r\n    submission = submission.tolist()\r\n    submission = [str(x[0])+\",\"+str(x[1][0])+\" \"+str(x[1][1])+\" \"+str(x[1][2])+\" \"+str(x[1][3])+\" \"+str(x[1][4]) for x in submission]",
    "122874": "Shahnawaz,\r\n\r\nThank you.  I tried to convert from numpy to a list at first, but did not know about the list comprehension you demonstrated.  That's a simpler and better way to do it!"
  },
  "source": "meta"
}