title: How to cast RGB to float arrays in Python
body: <p>I have an image that I need to save into the RGB type described below.</p>
  <pre><code>RGB_DTYPE = np.dtype({'names': ['R', 'G', 'B'],
                    'formats': [np.uint8, np.uint8, np.uint8]})
  
  x = get_image_from_jpg(in_fname)  # float 32 numpy array, with shape [128, 128, 3]
  x = do_some_computation(x)  # do some computation before saving
  x_rgb = x.astype(RGB_DTYPE)  # RGB dtype to save the image into the right format
  save_rgb_image(x_rgb, out_fname)  # save the image on the disk
  </code></pre>
  <p>After that, when I load the image from the disk, I need to convert it to float32 to run computations with standard Python libraries.</p>
  <pre><code>x_rgb = load_rgb_image(out_fname)  # load image 
  print(x_rgb.dtype)  # returns: [('R', 'u1'), ('G', 'u1'), ('B', 'u1')]
  x = x_rgb.astype(np.float32)  # --&gt; ERROR
  </code></pre>
  <p>However, I get the following error, which I don't understand how to solve:</p>
  <pre><code>Traceback (most recent call last):
  File &quot;&lt;input&gt;&quot;, line 1, in &lt;module&gt;
  TypeError: Cannot cast array data from dtype([('R', 'u1'), ('G', 'u1'), ('B', 'u1')]) to dtype('float32') according to the rule 'unsafe'
  </code></pre>
  <p>Any idea what this is and how to solve it?</p>