title: How do you create a (sometimes) ragged array of arrays in Numpy?
body: <p>In Numpy, I want to create an array of integer arrays (or lists).  Each individual array is a set of indices.  These individual arrays generally have different lengths, but sometimes all have the same length.</p>
  <p>When the lengths are different, I can create the array as</p>
  <pre><code>test = np.array([[1,2],[1,2,3]],dtype=object)
  </code></pre>
  <p>When I do this, <code>test[0]</code> is a list of integers and I can use <code>other_array[test[0]]</code> without issue.</p>
  <p>However, when <code>test</code> happens to have entries all the same size and I do</p>
  <pre><code>test = np.array([[1,2],[1,3]], dtype=object)
  </code></pre>
  <p>then <code>test[0]</code> is a Numpy array of dtype <code>object</code>.  When I use <code>other_array[test[0]]</code> I get an error that <code>arrays used as indices must be of integer (or boolean) type</code>.</p>
  <p>Here is a complete example:</p>
  <pre><code>other_array = np.array([0,1,2,3])
  test1 = np.array([[1,2],[1,2,3]], dtype=object)
  print(other_array[test1[0]]) #this works
  
  test2 = np.array([[1,2],[1,3]], dtype=object)
  print(other_array[test2[0]]) #this fails
  </code></pre>
  <p>The only way I have found around this issue is to check if <code>test</code> will be ragged or not before creating it and use <code>dtype=int</code> when it happens to have arrays of all the same size.  This seems inefficient.  Is there a generic way to create an array of integer arrays that is sometimes ragged and sometimes not without checking for raggedness?</p>