title: How to do numpy multidimensional indexing with 2D indexing array of variable internal sizes
body: <p>I am trying to create a smoothing algorithm in Blender for UVs with NumPy. I have 2 NumPy arrays. One is of shape [n,2] called &quot;uv_list&quot; where 'n' is the number of vertices selected. The other's shape is [n,x]  called &quot;connected_ind&quot; where x is the number of other vertices connected to the vertex of the index with each x being a NumPy array of variable size.</p>
  <p>Example of arrays (as printed out from my program):</p>
  <pre><code>uv_list = [[0.         0.        ]
  [0.57460427 0.4089092 ]
  [0.48790365 0.45793641]
  ...
  [0.55694079 0.39607367]
  [0.56155378 0.40128589]
  [0.56588227 0.40614387]]
  
  connected_ind: [array([ 28, 103, 147,  29,  74]) array([ 44, 224,  43,  73, 193])
   array([ 14, 104, 254,  58, 223]) ...
   array([2605, 2607, 2592, 2593,   40,   41])
   array([2606, 2608, 2593, 2594,   41,   42])
   array([  43,   44, 2607, 2594,   45,   42])]
  </code></pre>
  <p>How would I then get another numpy array  of shape [n,x,2] filled with uvs? Or put another way how can I index uv_list in such a way that I get arrays of uvs that I can then np.average or np.mean?</p>
  <p>Example of array to average (as I assume it would/should look):</p>
  <pre><code>indexed_uvs = [
  array([0.1234, 0.5678],[0.5879,0.3564],[0.2548,0.7512]),
  array([0.9124, 0.1248],[0.8654,0.1245],[0.7415,0.3698],[0.2548,0.5814]),
  ...
  array([0.6578, 0.1245]),
  array([0.3784, 0.6575],[0.8456,0.2134])
  ]
  </code></pre>
  <p>Which I would then want to average each line and have an array of shape [n,2] to assign back to the vertices:</p>
  <pre><code>np.average(indexed_uvs, axis=1)
  </code></pre>
  <p>What I've tried so far is &quot;uvs[ind]&quot; but that returns an error of:</p>
  <blockquote>
  <p>IndexError: arrays used as indices must be of integer (or boolean) type</p>
  </blockquote>
  <p>I assume it's because each array of connected_ind is stored as a ndarray due to each array being different sizes but not sure how to fix this. I tried using a plain python list of lists for connected_ind but I get roughly the same error:</p>
  <blockquote>
  <p>IndexError: only integers, slices (<code>:</code>), ellipsis (<code>...</code>),
  numpy.newaxis (<code>None</code>) and integer or boolean arrays are valid indices</p>
  </blockquote>
  <p>Code that should simulate my problem:</p>
  <pre><code>import numpy as np
  import random
  
  i = 10
  n = 20
  
  # Simulate my array of uvs ( list of floats, shape = [n,2] )
  uv_list = np.random.random_sample([n,2])
  
  # Simulate my array of indices ( list of variable sized lists of ints, shape = [n,x] )
  x = np.random.randint(1,high=7,size=n)
  connected_ind = np.array( [ np.array( [np.random.randint(0,high=n) for _ in range(num)] ) for num in x] )
  
  # Simulate an array of indices with same sized lists at dimension 1
  #connected_ind = np.random.randint(0,high=n,size=[n,4])
  
  for _ in range(i):
      print(_)
      # Get list of uvs by list of indices
      indexed_uvs = uv_list[connected_ind] # ERRORS HERE
  
      # Average each row of uv coordinates
      uv_list = np.average(indexed_uvs, axis=1)
  </code></pre>
  <p>Thanks for any help!</p>