title: Indexing a numpy ndarray with a numpy ndarray
body: <p>I am doing a tutorial with the iris dataset. In this process, I have found a piece of code, that I can't make sense of:</p>
  
  <p><strong>It consists of two ndarrays:</strong></p>
  
  <p><code>iris.target_names</code> is a numpy ndarray with the labels of the target variable:</p>
  
  <pre><code>iris.target_names
  &gt;&gt;&gt; array(['setosa', 'versicolor', 'virginica'], dtype='&lt;U10')
  </code></pre>
  
  <p><code>clf.predict(test[features])</code> is a numpy ndarray with the encoded digitis of my predictions:</p>
  
  <pre><code>clf.predict(test[features])
  &gt;&gt;&gt; array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
     1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2],
    dtype=int64)
  </code></pre>
  
  <p><strong>The following code creates a labeled ndarray for my predictions:</strong></p>
  
  <pre><code>iris.target_names[clf.predict(test[features])]
  &gt;&gt;&gt; array(['setosa', 'setosa', 'setosa', 'setosa', 'setosa', 'setosa', 
  'setosa', 'setosa', 'setosa', 'setosa', 'setosa', 'setosa', 'setosa', 
  'setosa', 'setosa', 'versicolor', 'versicolor', 'versicolor', 'versicolor',  
  'versicolor', 'versicolor', (...), dtype='&lt;U10')
  </code></pre>
  
  <p>I have thought about it for some time, but I don't understand how this works. Because actually we index a 1-dimensional array with three elements by a 1-dimensional array with more than three elements, right? How can this work? </p>
  
  <p>Would be great if someone could help me with some hints on this topic.</p>
  
  <p>Thanks, Marcus</p>