Incorrect Mode Calculation or is this salt and pepper?











up vote
1
down vote

favorite












I have a very simple usecase, I am gridding an image and calculating the most frequent occurring colour in each cell.



enter image description here



I have a problem where certain cells that visually look like black should be the most frequent colour have a mode of white (255). An example of this is cell (6,3) - zero-based index column first then row.



It should be black shouldn't it but it turns out white. Is there an issue with my code or is there salt and pepper noise I cannot see?



def mode_filter(self, roi):
values = np.zeros((1, 256), dtype="uint8")

for pos, val in np.ndenumerate(roi):
values[0, val] += 1

print(values)
return int(np.argmax(values[0]))

def get_roi(self, src, pt1, pt2):

col1, col2 = (pt1[0], pt2[0]) if pt1[0] < pt2[0] else (pt2[0], pt1[0])
row1, row2 = (pt1[1], pt2[1]) if pt1[1] < pt2[1] else (pt2[1], pt1[1])
return src[row1:row2, col1:col2]

def grid_img(self, src, nCols=7, nRows=7):

gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
cells = np.zeros(gray.shape, dtype="uint8")
cell_w = int(gray.shape[1] / nCols)
cell_h = int(gray.shape[0] / nRows)

for c in range(nCols):
for r in range(nRows):
roi = self.get_roi(gray, (c*cell_w, r*cell_h), ((c+1)*cell_w, (r+1)*cell_h))

mode = self.mode_filter(roi)
cv2.rectangle(cells, (c*cell_w, r*cell_h), ((c+1)*cell_w, (r+1)*cell_h), (mode,), -1)

cv2.imshow('roi', roi)
cv2.imshow('cells', cells)
cv2.imshow('src', src)
print('{}, {}'.format((c,r), mode))
cv2.waitKey(0)

return cells


A full working example can be found here: https://pastebin.com/k7kUTmXG



enter image description here










share|improve this question


























    up vote
    1
    down vote

    favorite












    I have a very simple usecase, I am gridding an image and calculating the most frequent occurring colour in each cell.



    enter image description here



    I have a problem where certain cells that visually look like black should be the most frequent colour have a mode of white (255). An example of this is cell (6,3) - zero-based index column first then row.



    It should be black shouldn't it but it turns out white. Is there an issue with my code or is there salt and pepper noise I cannot see?



    def mode_filter(self, roi):
    values = np.zeros((1, 256), dtype="uint8")

    for pos, val in np.ndenumerate(roi):
    values[0, val] += 1

    print(values)
    return int(np.argmax(values[0]))

    def get_roi(self, src, pt1, pt2):

    col1, col2 = (pt1[0], pt2[0]) if pt1[0] < pt2[0] else (pt2[0], pt1[0])
    row1, row2 = (pt1[1], pt2[1]) if pt1[1] < pt2[1] else (pt2[1], pt1[1])
    return src[row1:row2, col1:col2]

    def grid_img(self, src, nCols=7, nRows=7):

    gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
    cells = np.zeros(gray.shape, dtype="uint8")
    cell_w = int(gray.shape[1] / nCols)
    cell_h = int(gray.shape[0] / nRows)

    for c in range(nCols):
    for r in range(nRows):
    roi = self.get_roi(gray, (c*cell_w, r*cell_h), ((c+1)*cell_w, (r+1)*cell_h))

    mode = self.mode_filter(roi)
    cv2.rectangle(cells, (c*cell_w, r*cell_h), ((c+1)*cell_w, (r+1)*cell_h), (mode,), -1)

    cv2.imshow('roi', roi)
    cv2.imshow('cells', cells)
    cv2.imshow('src', src)
    print('{}, {}'.format((c,r), mode))
    cv2.waitKey(0)

    return cells


    A full working example can be found here: https://pastebin.com/k7kUTmXG



    enter image description here










    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have a very simple usecase, I am gridding an image and calculating the most frequent occurring colour in each cell.



      enter image description here



      I have a problem where certain cells that visually look like black should be the most frequent colour have a mode of white (255). An example of this is cell (6,3) - zero-based index column first then row.



      It should be black shouldn't it but it turns out white. Is there an issue with my code or is there salt and pepper noise I cannot see?



      def mode_filter(self, roi):
      values = np.zeros((1, 256), dtype="uint8")

      for pos, val in np.ndenumerate(roi):
      values[0, val] += 1

      print(values)
      return int(np.argmax(values[0]))

      def get_roi(self, src, pt1, pt2):

      col1, col2 = (pt1[0], pt2[0]) if pt1[0] < pt2[0] else (pt2[0], pt1[0])
      row1, row2 = (pt1[1], pt2[1]) if pt1[1] < pt2[1] else (pt2[1], pt1[1])
      return src[row1:row2, col1:col2]

      def grid_img(self, src, nCols=7, nRows=7):

      gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
      cells = np.zeros(gray.shape, dtype="uint8")
      cell_w = int(gray.shape[1] / nCols)
      cell_h = int(gray.shape[0] / nRows)

      for c in range(nCols):
      for r in range(nRows):
      roi = self.get_roi(gray, (c*cell_w, r*cell_h), ((c+1)*cell_w, (r+1)*cell_h))

      mode = self.mode_filter(roi)
      cv2.rectangle(cells, (c*cell_w, r*cell_h), ((c+1)*cell_w, (r+1)*cell_h), (mode,), -1)

      cv2.imshow('roi', roi)
      cv2.imshow('cells', cells)
      cv2.imshow('src', src)
      print('{}, {}'.format((c,r), mode))
      cv2.waitKey(0)

      return cells


      A full working example can be found here: https://pastebin.com/k7kUTmXG



      enter image description here










      share|improve this question













      I have a very simple usecase, I am gridding an image and calculating the most frequent occurring colour in each cell.



      enter image description here



      I have a problem where certain cells that visually look like black should be the most frequent colour have a mode of white (255). An example of this is cell (6,3) - zero-based index column first then row.



      It should be black shouldn't it but it turns out white. Is there an issue with my code or is there salt and pepper noise I cannot see?



      def mode_filter(self, roi):
      values = np.zeros((1, 256), dtype="uint8")

      for pos, val in np.ndenumerate(roi):
      values[0, val] += 1

      print(values)
      return int(np.argmax(values[0]))

      def get_roi(self, src, pt1, pt2):

      col1, col2 = (pt1[0], pt2[0]) if pt1[0] < pt2[0] else (pt2[0], pt1[0])
      row1, row2 = (pt1[1], pt2[1]) if pt1[1] < pt2[1] else (pt2[1], pt1[1])
      return src[row1:row2, col1:col2]

      def grid_img(self, src, nCols=7, nRows=7):

      gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
      cells = np.zeros(gray.shape, dtype="uint8")
      cell_w = int(gray.shape[1] / nCols)
      cell_h = int(gray.shape[0] / nRows)

      for c in range(nCols):
      for r in range(nRows):
      roi = self.get_roi(gray, (c*cell_w, r*cell_h), ((c+1)*cell_w, (r+1)*cell_h))

      mode = self.mode_filter(roi)
      cv2.rectangle(cells, (c*cell_w, r*cell_h), ((c+1)*cell_w, (r+1)*cell_h), (mode,), -1)

      cv2.imshow('roi', roi)
      cv2.imshow('cells', cells)
      cv2.imshow('src', src)
      print('{}, {}'.format((c,r), mode))
      cv2.waitKey(0)

      return cells


      A full working example can be found here: https://pastebin.com/k7kUTmXG



      enter image description here







      python numpy opencv






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 7 at 15:46









      Jake M

      7,06942129240




      7,06942129240
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          The definition of the array you use to count the number of occurrences of each colour is as follows:



          values = np.zeros((1, 256), dtype="uint8")


          That means that each count is represented by a single byte, meaning the maximum value is 255. Once an additional pixel of that colour appears, the count will overflow to 0.



          This is pretty much guaranteed to happen, as the size of the ROI you're processing is ~ 100x100 pixels.



          The solution is simple -- use a bigger data type, such as int32.



          def mode_filter(self, roi):
          values = np.zeros((1, 256), dtype="int32")

          for pos, val in np.ndenumerate(roi):
          values[0, val] += 1

          print(values)
          return int(np.argmax(values[0]))




          For example, on tile (0,5), which looks like this:



          Tile (0,5)



          your function gives the following output:



          [[144  15   9  13   8   1   5   9   4   5   5   1   2   4   4   4   4   6
          7 5 4 2 1 2 1 1 0 1 2 1 6 3 4 7 2 3
          1 1 2 1 0 4 2 2 3 2 0 2 0 2 0 1 2 5
          1 3 2 4 2 2 3 3 1 3 4 2 2 2 2 4 3 2
          4 0 1 2 0 2 2 2 1 0 2 2 1 1 2 1 0 3
          2 0 1 1 0 4 1 3 1 2 3 1 0 3 0 1 1 0
          0 1 2 1 2 0 1 2 2 1 1 0 1 2 2 4 2 1
          2 1 1 1 1 2 1 1 1 3 1 1 2 3 2 1 2 0
          1 1 1 3 4 2 3 1 1 2 1 1 5 3 1 2 1 1
          1 0 2 3 0 1 1 3 4 0 2 1 4 3 0 1 4 1
          1 2 2 1 0 1 1 2 1 1 1 3 2 3 1 5 0 2
          2 1 2 2 0 2 1 0 1 1 4 2 4 2 2 4 1 4
          4 4 1 3 1 0 3 6 3 2 0 2 3 5 3 3 5 5
          5 4 3 6 7 4 1 7 2 10 5 10 6 10 7 7 16 8
          10 14 16 125]]
          0


          whereas the corrected version produces this:



          [[2960   15    9   13    8    1    5    9    4    5    5    1    2    4
          4 4 4 6 7 5 4 2 1 2 1 1 0 1
          2 1 6 3 4 7 2 3 1 1 2 1 0 4
          2 2 3 2 0 2 0 2 0 1 2 5 1 3
          2 4 2 2 3 3 1 3 4 2 2 2 2 4
          3 2 4 0 1 2 0 2 2 2 1 0 2 2
          1 1 2 1 0 3 2 0 1 1 0 4 1 3
          1 2 3 1 0 3 0 1 1 0 0 1 2 1
          2 0 1 2 2 1 1 0 1 2 2 4 2 1
          2 1 1 1 1 2 1 1 1 3 1 1 2 3
          2 1 2 0 1 1 1 3 4 2 3 1 1 2
          1 1 5 3 1 2 1 1 1 0 2 3 0 1
          1 3 4 0 2 1 4 3 0 1 4 1 1 2
          2 1 0 1 1 2 1 1 1 3 2 3 1 5
          0 2 2 1 2 2 0 2 1 0 1 1 4 2
          4 2 2 4 1 4 4 4 1 3 1 0 3 6
          3 2 0 2 3 5 3 3 5 5 5 4 3 6
          7 4 1 7 2 10 5 10 6 10 7 7 16 8
          10 14 16 7293]]
          255





          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',
            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%2f53192910%2fincorrect-mode-calculation-or-is-this-salt-and-pepper%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








            up vote
            3
            down vote



            accepted










            The definition of the array you use to count the number of occurrences of each colour is as follows:



            values = np.zeros((1, 256), dtype="uint8")


            That means that each count is represented by a single byte, meaning the maximum value is 255. Once an additional pixel of that colour appears, the count will overflow to 0.



            This is pretty much guaranteed to happen, as the size of the ROI you're processing is ~ 100x100 pixels.



            The solution is simple -- use a bigger data type, such as int32.



            def mode_filter(self, roi):
            values = np.zeros((1, 256), dtype="int32")

            for pos, val in np.ndenumerate(roi):
            values[0, val] += 1

            print(values)
            return int(np.argmax(values[0]))




            For example, on tile (0,5), which looks like this:



            Tile (0,5)



            your function gives the following output:



            [[144  15   9  13   8   1   5   9   4   5   5   1   2   4   4   4   4   6
            7 5 4 2 1 2 1 1 0 1 2 1 6 3 4 7 2 3
            1 1 2 1 0 4 2 2 3 2 0 2 0 2 0 1 2 5
            1 3 2 4 2 2 3 3 1 3 4 2 2 2 2 4 3 2
            4 0 1 2 0 2 2 2 1 0 2 2 1 1 2 1 0 3
            2 0 1 1 0 4 1 3 1 2 3 1 0 3 0 1 1 0
            0 1 2 1 2 0 1 2 2 1 1 0 1 2 2 4 2 1
            2 1 1 1 1 2 1 1 1 3 1 1 2 3 2 1 2 0
            1 1 1 3 4 2 3 1 1 2 1 1 5 3 1 2 1 1
            1 0 2 3 0 1 1 3 4 0 2 1 4 3 0 1 4 1
            1 2 2 1 0 1 1 2 1 1 1 3 2 3 1 5 0 2
            2 1 2 2 0 2 1 0 1 1 4 2 4 2 2 4 1 4
            4 4 1 3 1 0 3 6 3 2 0 2 3 5 3 3 5 5
            5 4 3 6 7 4 1 7 2 10 5 10 6 10 7 7 16 8
            10 14 16 125]]
            0


            whereas the corrected version produces this:



            [[2960   15    9   13    8    1    5    9    4    5    5    1    2    4
            4 4 4 6 7 5 4 2 1 2 1 1 0 1
            2 1 6 3 4 7 2 3 1 1 2 1 0 4
            2 2 3 2 0 2 0 2 0 1 2 5 1 3
            2 4 2 2 3 3 1 3 4 2 2 2 2 4
            3 2 4 0 1 2 0 2 2 2 1 0 2 2
            1 1 2 1 0 3 2 0 1 1 0 4 1 3
            1 2 3 1 0 3 0 1 1 0 0 1 2 1
            2 0 1 2 2 1 1 0 1 2 2 4 2 1
            2 1 1 1 1 2 1 1 1 3 1 1 2 3
            2 1 2 0 1 1 1 3 4 2 3 1 1 2
            1 1 5 3 1 2 1 1 1 0 2 3 0 1
            1 3 4 0 2 1 4 3 0 1 4 1 1 2
            2 1 0 1 1 2 1 1 1 3 2 3 1 5
            0 2 2 1 2 2 0 2 1 0 1 1 4 2
            4 2 2 4 1 4 4 4 1 3 1 0 3 6
            3 2 0 2 3 5 3 3 5 5 5 4 3 6
            7 4 1 7 2 10 5 10 6 10 7 7 16 8
            10 14 16 7293]]
            255





            share|improve this answer

























              up vote
              3
              down vote



              accepted










              The definition of the array you use to count the number of occurrences of each colour is as follows:



              values = np.zeros((1, 256), dtype="uint8")


              That means that each count is represented by a single byte, meaning the maximum value is 255. Once an additional pixel of that colour appears, the count will overflow to 0.



              This is pretty much guaranteed to happen, as the size of the ROI you're processing is ~ 100x100 pixels.



              The solution is simple -- use a bigger data type, such as int32.



              def mode_filter(self, roi):
              values = np.zeros((1, 256), dtype="int32")

              for pos, val in np.ndenumerate(roi):
              values[0, val] += 1

              print(values)
              return int(np.argmax(values[0]))




              For example, on tile (0,5), which looks like this:



              Tile (0,5)



              your function gives the following output:



              [[144  15   9  13   8   1   5   9   4   5   5   1   2   4   4   4   4   6
              7 5 4 2 1 2 1 1 0 1 2 1 6 3 4 7 2 3
              1 1 2 1 0 4 2 2 3 2 0 2 0 2 0 1 2 5
              1 3 2 4 2 2 3 3 1 3 4 2 2 2 2 4 3 2
              4 0 1 2 0 2 2 2 1 0 2 2 1 1 2 1 0 3
              2 0 1 1 0 4 1 3 1 2 3 1 0 3 0 1 1 0
              0 1 2 1 2 0 1 2 2 1 1 0 1 2 2 4 2 1
              2 1 1 1 1 2 1 1 1 3 1 1 2 3 2 1 2 0
              1 1 1 3 4 2 3 1 1 2 1 1 5 3 1 2 1 1
              1 0 2 3 0 1 1 3 4 0 2 1 4 3 0 1 4 1
              1 2 2 1 0 1 1 2 1 1 1 3 2 3 1 5 0 2
              2 1 2 2 0 2 1 0 1 1 4 2 4 2 2 4 1 4
              4 4 1 3 1 0 3 6 3 2 0 2 3 5 3 3 5 5
              5 4 3 6 7 4 1 7 2 10 5 10 6 10 7 7 16 8
              10 14 16 125]]
              0


              whereas the corrected version produces this:



              [[2960   15    9   13    8    1    5    9    4    5    5    1    2    4
              4 4 4 6 7 5 4 2 1 2 1 1 0 1
              2 1 6 3 4 7 2 3 1 1 2 1 0 4
              2 2 3 2 0 2 0 2 0 1 2 5 1 3
              2 4 2 2 3 3 1 3 4 2 2 2 2 4
              3 2 4 0 1 2 0 2 2 2 1 0 2 2
              1 1 2 1 0 3 2 0 1 1 0 4 1 3
              1 2 3 1 0 3 0 1 1 0 0 1 2 1
              2 0 1 2 2 1 1 0 1 2 2 4 2 1
              2 1 1 1 1 2 1 1 1 3 1 1 2 3
              2 1 2 0 1 1 1 3 4 2 3 1 1 2
              1 1 5 3 1 2 1 1 1 0 2 3 0 1
              1 3 4 0 2 1 4 3 0 1 4 1 1 2
              2 1 0 1 1 2 1 1 1 3 2 3 1 5
              0 2 2 1 2 2 0 2 1 0 1 1 4 2
              4 2 2 4 1 4 4 4 1 3 1 0 3 6
              3 2 0 2 3 5 3 3 5 5 5 4 3 6
              7 4 1 7 2 10 5 10 6 10 7 7 16 8
              10 14 16 7293]]
              255





              share|improve this answer























                up vote
                3
                down vote



                accepted







                up vote
                3
                down vote



                accepted






                The definition of the array you use to count the number of occurrences of each colour is as follows:



                values = np.zeros((1, 256), dtype="uint8")


                That means that each count is represented by a single byte, meaning the maximum value is 255. Once an additional pixel of that colour appears, the count will overflow to 0.



                This is pretty much guaranteed to happen, as the size of the ROI you're processing is ~ 100x100 pixels.



                The solution is simple -- use a bigger data type, such as int32.



                def mode_filter(self, roi):
                values = np.zeros((1, 256), dtype="int32")

                for pos, val in np.ndenumerate(roi):
                values[0, val] += 1

                print(values)
                return int(np.argmax(values[0]))




                For example, on tile (0,5), which looks like this:



                Tile (0,5)



                your function gives the following output:



                [[144  15   9  13   8   1   5   9   4   5   5   1   2   4   4   4   4   6
                7 5 4 2 1 2 1 1 0 1 2 1 6 3 4 7 2 3
                1 1 2 1 0 4 2 2 3 2 0 2 0 2 0 1 2 5
                1 3 2 4 2 2 3 3 1 3 4 2 2 2 2 4 3 2
                4 0 1 2 0 2 2 2 1 0 2 2 1 1 2 1 0 3
                2 0 1 1 0 4 1 3 1 2 3 1 0 3 0 1 1 0
                0 1 2 1 2 0 1 2 2 1 1 0 1 2 2 4 2 1
                2 1 1 1 1 2 1 1 1 3 1 1 2 3 2 1 2 0
                1 1 1 3 4 2 3 1 1 2 1 1 5 3 1 2 1 1
                1 0 2 3 0 1 1 3 4 0 2 1 4 3 0 1 4 1
                1 2 2 1 0 1 1 2 1 1 1 3 2 3 1 5 0 2
                2 1 2 2 0 2 1 0 1 1 4 2 4 2 2 4 1 4
                4 4 1 3 1 0 3 6 3 2 0 2 3 5 3 3 5 5
                5 4 3 6 7 4 1 7 2 10 5 10 6 10 7 7 16 8
                10 14 16 125]]
                0


                whereas the corrected version produces this:



                [[2960   15    9   13    8    1    5    9    4    5    5    1    2    4
                4 4 4 6 7 5 4 2 1 2 1 1 0 1
                2 1 6 3 4 7 2 3 1 1 2 1 0 4
                2 2 3 2 0 2 0 2 0 1 2 5 1 3
                2 4 2 2 3 3 1 3 4 2 2 2 2 4
                3 2 4 0 1 2 0 2 2 2 1 0 2 2
                1 1 2 1 0 3 2 0 1 1 0 4 1 3
                1 2 3 1 0 3 0 1 1 0 0 1 2 1
                2 0 1 2 2 1 1 0 1 2 2 4 2 1
                2 1 1 1 1 2 1 1 1 3 1 1 2 3
                2 1 2 0 1 1 1 3 4 2 3 1 1 2
                1 1 5 3 1 2 1 1 1 0 2 3 0 1
                1 3 4 0 2 1 4 3 0 1 4 1 1 2
                2 1 0 1 1 2 1 1 1 3 2 3 1 5
                0 2 2 1 2 2 0 2 1 0 1 1 4 2
                4 2 2 4 1 4 4 4 1 3 1 0 3 6
                3 2 0 2 3 5 3 3 5 5 5 4 3 6
                7 4 1 7 2 10 5 10 6 10 7 7 16 8
                10 14 16 7293]]
                255





                share|improve this answer












                The definition of the array you use to count the number of occurrences of each colour is as follows:



                values = np.zeros((1, 256), dtype="uint8")


                That means that each count is represented by a single byte, meaning the maximum value is 255. Once an additional pixel of that colour appears, the count will overflow to 0.



                This is pretty much guaranteed to happen, as the size of the ROI you're processing is ~ 100x100 pixels.



                The solution is simple -- use a bigger data type, such as int32.



                def mode_filter(self, roi):
                values = np.zeros((1, 256), dtype="int32")

                for pos, val in np.ndenumerate(roi):
                values[0, val] += 1

                print(values)
                return int(np.argmax(values[0]))




                For example, on tile (0,5), which looks like this:



                Tile (0,5)



                your function gives the following output:



                [[144  15   9  13   8   1   5   9   4   5   5   1   2   4   4   4   4   6
                7 5 4 2 1 2 1 1 0 1 2 1 6 3 4 7 2 3
                1 1 2 1 0 4 2 2 3 2 0 2 0 2 0 1 2 5
                1 3 2 4 2 2 3 3 1 3 4 2 2 2 2 4 3 2
                4 0 1 2 0 2 2 2 1 0 2 2 1 1 2 1 0 3
                2 0 1 1 0 4 1 3 1 2 3 1 0 3 0 1 1 0
                0 1 2 1 2 0 1 2 2 1 1 0 1 2 2 4 2 1
                2 1 1 1 1 2 1 1 1 3 1 1 2 3 2 1 2 0
                1 1 1 3 4 2 3 1 1 2 1 1 5 3 1 2 1 1
                1 0 2 3 0 1 1 3 4 0 2 1 4 3 0 1 4 1
                1 2 2 1 0 1 1 2 1 1 1 3 2 3 1 5 0 2
                2 1 2 2 0 2 1 0 1 1 4 2 4 2 2 4 1 4
                4 4 1 3 1 0 3 6 3 2 0 2 3 5 3 3 5 5
                5 4 3 6 7 4 1 7 2 10 5 10 6 10 7 7 16 8
                10 14 16 125]]
                0


                whereas the corrected version produces this:



                [[2960   15    9   13    8    1    5    9    4    5    5    1    2    4
                4 4 4 6 7 5 4 2 1 2 1 1 0 1
                2 1 6 3 4 7 2 3 1 1 2 1 0 4
                2 2 3 2 0 2 0 2 0 1 2 5 1 3
                2 4 2 2 3 3 1 3 4 2 2 2 2 4
                3 2 4 0 1 2 0 2 2 2 1 0 2 2
                1 1 2 1 0 3 2 0 1 1 0 4 1 3
                1 2 3 1 0 3 0 1 1 0 0 1 2 1
                2 0 1 2 2 1 1 0 1 2 2 4 2 1
                2 1 1 1 1 2 1 1 1 3 1 1 2 3
                2 1 2 0 1 1 1 3 4 2 3 1 1 2
                1 1 5 3 1 2 1 1 1 0 2 3 0 1
                1 3 4 0 2 1 4 3 0 1 4 1 1 2
                2 1 0 1 1 2 1 1 1 3 2 3 1 5
                0 2 2 1 2 2 0 2 1 0 1 1 4 2
                4 2 2 4 1 4 4 4 1 3 1 0 3 6
                3 2 0 2 3 5 3 3 5 5 5 4 3 6
                7 4 1 7 2 10 5 10 6 10 7 7 16 8
                10 14 16 7293]]
                255






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 7 at 16:32









                Dan Mašek

                8,54432445




                8,54432445






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53192910%2fincorrect-mode-calculation-or-is-this-salt-and-pepper%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







                    這個網誌中的熱門文章

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud

                    Zucchini