title: Numpy: Using a matrix as indices for another matrix to create a tensor?
body: <p>how would the following code work? </p>
  
  <pre><code>k = np.array([[ 0.,          0.07142857,  0.14285714],
                [ 0.21428571,  0.28571429,  0.35714286],
                [ 0.42857143,  0.5,         0.57142857],
                [ 0.64285714,  0.71428571,  0.78571429],
                [ 0.85714286,  0.92857143,  1.        ]])
  y = np.array([[0, 3, 1, 2],
                [2, 1, 0, 3]])
  b = k[y]
  </code></pre>
  
  <p>The shapes are:</p>
  
  <blockquote>
    <blockquote>
      <blockquote>
        <p>k shape: (5, 3)</p>
        
        <p>y shape: (2, 4)</p>
        
        <p>b shape: (2, 4, 3)</p>
      </blockquote>
    </blockquote>
  </blockquote>
  
  <p>Why would a numpy matrix accept another matrix as its index and how would k find the correct output? Why is a tensor produced instead? </p>
  
  <p>The output of b is</p>
  
  <pre><code>  [[[ 0.          0.07142857  0.14285714]
    [ 0.64285714  0.71428571  0.78571429]
    [ 0.21428571  0.28571429  0.35714286]
    [ 0.42857143  0.5         0.57142857]]
  
   [[ 0.42857143  0.5         0.57142857]
    [ 0.21428571  0.28571429  0.35714286]
    [ 0.          0.07142857  0.14285714]
    [ 0.64285714  0.71428571  0.78571429]]]
  </code></pre>