title: Mean of every nth element of swift array
body: <p>I have an array, where I want the mean of every nth element, starting from a specific element (in this case every 4th, starting at 1). What's the fastest way to do this?</p>
  
  <p>My current method is a for loop with a looping switch statement, but I want to know if there's a quicker way.</p>
  
  <p>I wondered if something like this could work:</p>
  
  <pre><code>let num_array = [1,2,3,4,5,6,7,8]
  let mean4th = num_array[Array(stride(from: 1, to: num_array.count, by: 4))].reduce(0, +) / (num_array.count / 4)
  </code></pre>
  
  <p>Hoping to get <code>mean4th = 3</code> (i.e. (1 + 5)/2)</p>
  
  <p>This returns the error</p>
  
  <pre><code>Cannot subscript a value of type 'Array&lt;UInt8&gt;' with an index of type 'Array&lt;Int&gt;'
  </code></pre>
  
  <p>..which I'm struggling to get around</p>