title: How can I select a non-sequential subset elements from an array using Scala and Spark?
body: <p>In Python, this is how I would do it. </p>
  
  <pre><code>&gt;&gt;&gt; x
  array([10,  9,  8,  7,  6,  5,  4,  3,  2])
  &gt;&gt;&gt; x[np.array([3, 3, 1, 8])]
  array([7, 7, 9, 2])
  </code></pre>
  
  <p>This doesn't work in the Scala Spark shell:</p>
  
  <pre><code>scala&gt; val indices = Array(3,2,0)
  indices: Array[Int] = Array(3, 2, 0)
  
  scala&gt; val A = Array(10,11,12,13,14,15)
  A: Array[Int] = Array(10, 11, 12, 13, 14, 15)
  
  scala&gt; A(indices)
  &lt;console&gt;:28: error: type mismatch;
   found   : Array[Int]
   required: Int
                A(indices)
  </code></pre>
  
  <p>The foreach method doesn't work either:</p>
  
  <pre><code>scala&gt; indices.foreach(println(_))
  3
  2
  0
  
  scala&gt; indices.foreach(A(_))
  &lt;no output&gt;
  </code></pre>
  
  <p>What I want is the result of B:</p>
  
  <pre><code>scala&gt; val B = Array(A(3),A(2),A(0))
  B: Array[Int] = Array(13, 12, 10)
  </code></pre>
  
  <p>However, I don't want to hard code it like that because I don't know how long indices is or what would be in it.</p>