{
  "id": 50205,
  "title": "Evaluation Exception: Index was outside the bounds of the array.",
  "url": "/competitions/data-science-bowl-2018/discussion/50205",
  "author_name": "",
  "post_date": "2018-02-21T07:38:32.422220300Z",
  "votes": null,
  "comment_count": 2,
  "views": 0,
  "content": "<p>When submitted for evaluation, I keep getting this error 'Evaluation Exception: Index was outside the bounds of the array.'. Does anyone have a ​similar experience? </p>",
  "messages": [
    {
      "id": "285904",
      "postDate": "02/21/2018 07:38:32",
      "content": "<p>When submitted for evaluation, I keep getting this error 'Evaluation Exception: Index was outside the bounds of the array.'. Does anyone have a ​similar experience? </p>",
      "rawMarkdown": "When submitted for evaluation, I keep getting this error 'Evaluation Exception: Index was outside the bounds of the array.'. Does anyone have a ​similar experience?",
      "votes": null
    },
    {
      "id": "285995",
      "postDate": "02/21/2018 12:57:41",
      "content": "<pre><code>def run_length_encode(x):\nbs = np.where(x.T.flatten())[0]\n\nrle = []\nprev = -2\nfor b in bs:\n    if (b&gt;prev+1): rle.extend((b + 1, 0))\n    rle[-1] += 1\n    prev = b\n\n#https://www.kaggle.com/c/data-science-bowl-2018/discussion/48561#\nif len(rle)!=0 and rle[-1]+rle[-2] == x.size:\n    rle[-2] = rle[-2] -1  #print('xxx')\n\nrle = ' '.join([str(r) for r in rle])\nreturn rle\n</code></pre>",
      "rawMarkdown": "def run_length_encode(x):\n    bs = np.where(x.T.flatten())[0]\n\n    rle = []\n    prev = -2\n    for b in bs:\n        if (b&gt;prev+1): rle.extend((b + 1, 0))\n        rle[-1] += 1\n        prev = b\n\n    #https://www.kaggle.com/c/data-science-bowl-2018/discussion/48561#\n    if len(rle)!=0 and rle[-1]+rle[-2] == x.size:\n        rle[-2] = rle[-2] -1  #print('xxx')\n\n    rle = ' '.join([str(r) for r in rle])\n    return rle",
      "votes": null
    },
    {
      "id": "286093",
      "postDate": "02/21/2018 17:08:00",
      "content": "<p>Thanks Heng, but could you elaborate on it. The following is the code I used for run-length encoding, I copied it from the unet kernel</p>\n\n<pre><code>def rle_encoding(x):\n   dots = np.where(x.T.flatten() == 1)[0]\n   run_lengths = []\n   prev = -2\n   for b in dots:\n       if (b&amp;gt;prev+1): run_lengths.extend((b + 1, 0))\n       run_lengths[-1] += 1\n       prev = b\nreturn run_lengths\n</code></pre>",
      "rawMarkdown": "Thanks Heng, but could you elaborate on it. The following is the code I used for run-length encoding, I copied it from the unet kernel\n\n    def rle_encoding(x):\n       dots = np.where(x.T.flatten() == 1)[0]\n       run_lengths = []\n       prev = -2\n       for b in dots:\n           if (b&gt;prev+1): run_lengths.extend((b + 1, 0))\n           run_lengths[-1] += 1\n           prev = b\n    return run_lengths",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 285995,
      "author_name": "hengck23",
      "author_url": "",
      "post_date": "02/21/2018 12:57:41",
      "content": "<pre><code>def run_length_encode(x):\nbs = np.where(x.T.flatten())[0]\n\nrle = []\nprev = -2\nfor b in bs:\n    if (b&gt;prev+1): rle.extend((b + 1, 0))\n    rle[-1] += 1\n    prev = b\n\n#https://www.kaggle.com/c/data-science-bowl-2018/discussion/48561#\nif len(rle)!=0 and rle[-1]+rle[-2] == x.size:\n    rle[-2] = rle[-2] -1  #print('xxx')\n\nrle = ' '.join([str(r) for r in rle])\nreturn rle\n</code></pre>",
      "votes": null,
      "replies": [
        {
          "id": 286093,
          "author_name": "wt2ding",
          "author_url": "",
          "post_date": "02/21/2018 17:08:00",
          "content": "<p>Thanks Heng, but could you elaborate on it. The following is the code I used for run-length encoding, I copied it from the unet kernel</p>\n\n<pre><code>def rle_encoding(x):\n   dots = np.where(x.T.flatten() == 1)[0]\n   run_lengths = []\n   prev = -2\n   for b in dots:\n       if (b&amp;gt;prev+1): run_lengths.extend((b + 1, 0))\n       run_lengths[-1] += 1\n       prev = b\nreturn run_lengths\n</code></pre>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "285904": "When submitted for evaluation, I keep getting this error 'Evaluation Exception: Index was outside the bounds of the array.'. Does anyone have a ​similar experience?",
    "285995": "def run_length_encode(x):\n    bs = np.where(x.T.flatten())[0]\n\n    rle = []\n    prev = -2\n    for b in bs:\n        if (b&gt;prev+1): rle.extend((b + 1, 0))\n        rle[-1] += 1\n        prev = b\n\n    #https://www.kaggle.com/c/data-science-bowl-2018/discussion/48561#\n    if len(rle)!=0 and rle[-1]+rle[-2] == x.size:\n        rle[-2] = rle[-2] -1  #print('xxx')\n\n    rle = ' '.join([str(r) for r in rle])\n    return rle",
    "286093": "Thanks Heng, but could you elaborate on it. The following is the code I used for run-length encoding, I copied it from the unet kernel\n\n    def rle_encoding(x):\n       dots = np.where(x.T.flatten() == 1)[0]\n       run_lengths = []\n       prev = -2\n       for b in dots:\n           if (b&gt;prev+1): run_lengths.extend((b + 1, 0))\n           run_lengths[-1] += 1\n           prev = b\n    return run_lengths"
  },
  "source": "meta"
}