title: NumPy first and last element from array
body: <p>I am trying to dynamically get the first and last element from an array. </p>
  
  <p>So, let us suppose the array has 6 elements. </p>
  
  <pre><code>test = [1,23,4,6,7,8]
  </code></pre>
  
  <p>If I am trying to get the <code>first and last = 1,8</code>, <code>23,7</code> and <code>4,6</code>. Is there a way to get elements in this order? 
  I looked at a couple of questions <a href="https://stackoverflow.com/questions/12218796/python-slice-first-and-last-element-in-list">Link</a> <a href="https://stackoverflow.com/questions/930397/how-to-get-the-last-element-of-a-list">Link2</a>. I took help of these links and I came up with this prototype..</p>
  
  <pre><code>#!/usr/bin/env python
  
  import numpy
  
  test = [1,23,4,6,7,8]
  test1 = numpy.array([1,23,4,6,7,8])
  len_test = len(test)
  first_list = [0,1,2]
  len_first = len(first_list)
  second_list = [-1,-2,-3]
  len_second = len(second_list)
  
  for a in range(len_first):
          print numpy.array(test)[[first_list[a] , second_list[a]]]
          print test1[[first_list[a], second_list[a]]]
  </code></pre>
  
  <p>But this prototype won't scale for if you have more than 6 elements. So, I was wondering if there is way to dynamically get the pair of elements.</p>
  
  <p>Thanks!</p>