title: Finding the indices of a sub 2D array in a 2D array whose elements are above a thershold value
body: <p>I'm new to C language and will appreciate assistance in implementing the following problem.
  This is a very simple problem when using either matlab or python however I can't seem to either find a function library in C which has similar capabilities to numpy or the basic built in functions of matlab.</p>
  <p>Given a threshold value, an NxM size array filled with double size data (&quot;<strong>arr</strong>&quot;) and a smaller (k+1)x(k+1) &quot;<strong>window</strong>&quot; (sub-array, k&lt;N,M), we need to return the first indices of the sub array that the sum of its elements is equal or above the threshold value. The indices are the starting location of the sub array in the NxM array.</p>
  <p>I thought of the following implementation:</p>
  <ol>
  <li>running two for loops over <strong>arr</strong> until reaching row - win and col - win.</li>
  <li>for every row and col value, run another 2 more for loops with a stop condition equal to the window size.</li>
  <li>sum the values over the entire <strong>window</strong> and when done check if sum &gt;= threshold</li>
  <li>if so store row and col in array, break the loops and return the array</li>
  </ol>
  <pre><code>    int N = 10;
      int M = 20;
      int sum = 0;
      
      double arr[N][M];
      int k = 10;
      int threshold = 50;
      int row, col, win_row, win_col;
      
      for (row = 0; row &lt; N - k + 1; row++) {
          for (col = 0; row &lt; M - k + 1; col++) {
              for (win_row = row; win_row &lt; row + k + 1; win_row++) {
                  for (win_col = col; win_col &lt; col + k + 1; win_col++){
                      sum += arr[win_row][win_col];
                  }
              }
              if (sum &gt;= threshold ) {
                      break;
              else {
                      sum = 0;
                  }
          }
          }
      }
      
      int indx = {row,col};
      
      return indx;
  </code></pre>
  <p>for example for the the following 4x5 array, a threshold value of 30 and a k=1 window(2x2):</p>
  <pre><code>    arr[4][5] = { {1, 0 , 0 , 4},
                  { 0, 10, ,8 ,0 },
                  { 0, 9, ,8 ,0 },
                  { 1, 0, ,0 ,1 },
      }
  </code></pre>
  <p>the sum will of the elements of the sub array will be 35 and the function will return the indices:
  row = 1 and col = 1</p>
  <p>To me this implementation fills very clumsy using 4 for loops and not elegant. However I don't have a lot of experience in C and again would appreciate any help and feedback</p>
  <p>Can you recommend a better way to implement this problem ?</p>