title: Splitting interleaved data into separate channels' np.arrays?
body: <p>I have a binary file, that contains interleaved data; here is a Python script that will generate an example of it:</p>
  
  <p><code>test-np-array-il-split-01.py</code>:</p>
  
  <pre class="lang-python prettyprint-override"><code>#!/usr/bin/env python2
  # (also works with python3)
  
  # generate a test binary file with interleaved floats
  
  thebinfilename = "il3ch.binfile"
  
  import struct
  
  # https://docs.python.org/2/library/struct.html :  "=" native; "&lt;" little-endian; "&gt;" big-endian
  with open(thebinfilename, 'wb') as f:
    for ix in range(10):
      decremain = ix/100.0;
      for ic in range(3):
        thischannum = ic+1 + decremain;
        print(thischannum)
        f.write(struct.pack("=f", thischannum))
  </code></pre>
  
  <p>Basically, just run <code>python test-np-array-il-split-01.py</code>, and you will get a binary file <code>il3ch.binfile</code> in the same directory. This file basically has this sequence of floating numbers:</p>
  
  <blockquote>
    <p>1.0, 2.0, 3.0, 1.01, 2.01, 3.01, 1.02, 2.02, 3.02, 1.03, 2.03, 3.03, 1.04, 2.04, 3.04, 1.05, 2.05, 3.05, 1.06, 2.06, 3.06, 1.07, 2.07, 3.07, 1.08, 2.08, 3.08, 1.09, 2.09, 3.09</p>
  </blockquote>
  
  <p>... stored as binary floats.</p>
  
  <p>Basically, I want to obtain the individual channel data as separate numpy arrays, where the channels would be:</p>
  
  <ul>
  <li>Ch1: 1.0, 1.01, 1.02, 1.03, 1.04, ...</li>
  <li>Ch2: 2.0, 2.01, 2.02, 2.03, 2.04, ...</li>
  <li>Ch3: 3.0, 3.01, 3.02, 3.03, 3.04, ...</li>
  </ul>
  
  <p>So, I've tried to write the following script (place it in the same folder as <code>test-np-array-il-split-01.py</code> and <code>il3ch.binfile</code>):</p>
  
  <p><code>test-np-array-il-split-02.py</code>:</p>
  
  <pre class="lang-python prettyprint-override"><code>#!/usr/bin/env python2
  # (also works with python3)
  
  # read a test binary file with interleaved floats
  
  thebinfilename = "il3ch.binfile"
  
  import numpy as np
  
  dt = np.dtype( [ ('CH1', '&lt;f4'), ('CH2', '&lt;f4'), ('CH3', '&lt;f4') ] )
  bin_np_arr = np.fromfile(thebinfilename, dtype=dt)
  
  print(bin_np_arr.shape) # (10,)
  print(bin_np_arr)
  # [(1.  , 2.  , 3.  ) (1.01, 2.01, 3.01) (1.02, 2.02, 3.02)
  #  (1.03, 2.03, 3.03) (1.04, 2.04, 3.04) (1.05, 2.05, 3.05)
  #  (1.06, 2.06, 3.06) (1.07, 2.07, 3.07) (1.08, 2.08, 3.08)
  #  (1.09, 2.09, 3.09)]
  
  ch1, ch2, ch3 = bin_np_arr[:][0], bin_np_arr[:][1], bin_np_arr[:][2]
  
  print(ch1) # (1., 2., 3.) # -&gt; however, I want 1.0, 1.01, 1.02, 1.03 ... etc here!
  
  </code></pre>
  
  <p>So, the good thing is that by using the <code>np.dtype</code> specification, I can impose a sort of a structure that is in the data - however, as output I get np.array of (CH1, CH2, CH3) tuples, and I really cannot tell what do I need to do, to split this np.array.</p>
  
  <p>So my question is: how can I split the <code>bin_np_arr</code> np.array into three separate np.arrays, which will correspond to the individual channel data? Also, should I read in the <code>bin_np_arr</code> differently from file (e.g. so it has a different <code>.shape</code>), so its more amenable to this kind of a "per-channel" split?</p>