title: Passing a list to numpy.ix_, or how to slice a multidimensional array, when number of dimensions and selection criteria are not known beforehand?
body: <p>I want to slice a multidimensional array in Numpy.
  Suppose my array is a 5*5*5 array, and the slicing that I have in mind in theory can be done using numpy.ix_:</p>
  
  <pre><code>    s0 = [0,1,2]
      s1 = [1,2,3]
      s2 = [1,2,3]
      b = a[numpy.ix_(s0,s1,s2)]
  </code></pre>
  
  <p>The problem is that the dimension of the array, as well as the way I need to slice the array along different dimensions change within the programme (for example array 'a' might be 2,3,4,... dimensional, and s0, s1, ... also change), so the above code doesn't work as I like unless I can pass a list/tuple to numpy.ix_ like this:</p>
  
  <pre><code>    N = 3
      M = 3
      s = [np.ones(M).astype(int) for i in range(N)]
      s[0] = [0,1,2]
      s[1] = [1,2,3]
      s[2] = [1,2,3]        
      b = a[numpy.ix_(s)]
  </code></pre>
  
  <p>Which unfortunately doesn't work, because ix_ only accepts one dimensional objects (?). What's the best workaround? How to cleanly implement ix_ myself (or is there an easier way to do this?)?</p>