title: ValueError: When changing to a larger dtype, its size must be a divisor of the total size in bytes of the last axis of the array
body: <p>I'm running into the following exception when operating on a third-party-supplied numpy dataset:</p>
  
  <pre><code>ValueError: When changing to a larger dtype, its size must be a divisor of the total size in bytes of the last axis of the array
  </code></pre>
  
  <p>Under what circumstances will numpy raise this? My code is applying a view on the numpy array, where I'm trying to apply a structured <code>dtype</code> that matches the number of elements in a row.</p>
  
  <p>I'm seeing this error when the statement <code>X.view([('', X.dtype)] * X.shape[1])</code> is called inside a function <code>f</code> - but not in every call to this function <code>f</code>:</p>
  
  <pre><code>ipdb&gt; X.view([('', X.dtype)] * X.shape[1])
  *** ValueError: When changing to a larger dtype, its size must be a divisor of the total size in bytes of the last axis of the array.
  </code></pre>
  
  <p><code>X</code> is always an array with two axis (<code>len(X.shape)</code> is always 2), so you'd expect a structured <code>dtype</code> that is <code>X.shape[1]</code> long to fit the last axis (<code>X.shape[1]</code>).</p>
  
  <p>The exception does not happen for all datasets, so what causes numpy to throw this for <em>some</em> arrays but not others? I can't even see which .py numpy source code is throwing this error. </p>
  
  <p>I'm finding it hard to produce a MCVE for this, but I've narrowed this down to a <a href="https://colab.research.google.com/drive/1t_xnVzCcvbYEFT9qEDoY8Z_4lvubk-8D" rel="noreferrer">colab notebook</a> that is still a little large to post here.</p>
  
  <p>Here <code>X</code> is supposed to be a subset of the <code>iris</code> dataset, which I got from scikit learn.</p>
  
  <pre><code>from sklearn.datasets import load_iris
  X = load_iris().data
  </code></pre>
  
  <p>My code looks like this:</p>
  
  <pre><code>def f(X):
      X_rows = X.view([('', X.dtype)] * X.shape[1])
  
  def g(X):
      f(X)
  
  def h(X):
      f(X)
  
  # call the functions
  g(X) # this runs without a problem
  f(X) # this returns the error
  </code></pre>