Array Slicing [Sept. 6, 2012, 12:22 p.m.]
Extrcation of Elements or Arrays from an Array
Given an array, it is possible to copy elements (or contiguous parts of it) into another variable (or array). To do so, we must refer to the index (or indices) of the element. The number of indices required is the same as the number of dimensions of the array.
Slicing One-dimensioned Arrays
Let us first create a one-dimensioned array and copy an element of it. In Python, indexing starts with 0.
import numpy as np
x = array([1, 2, 3, 4, 5,6, 7, 8])
print x
[ 1, 2, 3, 4, 5, 6, 7, 8]
a = x[0]
print a
1
b = x[0:4]
print b
[1 2 3 4]