Creating NumPy Arrays and Exploring Their Attributes
We will directly start with NumPy without attempting to follow the normal approach of first learning Python and then moving up to NumPy. The reasons why I am following this approach is based on the following:
 Python is extremely easy to learn and use, and you can learn the Python programming language as you go along.
 Knowing Python is not a prerequisite to begin using NumPy if you are ready to learn as you go.
 Accomplishing simple tasks early is a great motivator to learn. Spending some time learning Python when NumPy is your actual goal may be dampener to learning.
There are some extremely good resources to learn NumPy (at least, much better than this course) and you may find them useful as wel as insightful. Start with NumPy and SciPy official documentation.
Importing NumPy Module
Before using NumPy in your code, you must first import the NumPy library. However, if you are using IPython with the pylab command line argument, this would have been already been imported into the default namespace. But importing explicitly a second time is not an error.
There are multiple ways a module can be imported. Here are some:

Importing a module into its own namespace. All functions contained in the module must be called by referring to its module name immediately followed by the function name.
import numpy
x = numpy.array([1, 2, 3, 4, 5])
print x
[1 2 3 4 5] 
Importing a module into its own namespace and simultaneously creating an alias for the namespace. The namespace now can be referred to by its original module name or the assigned alias.
import numpy as np
x = np.array([1, 2, 3, 4, 5])
print x
[1 2 3 4 5] 
Importing a module into the default namespace. All functions in the imported module now become a part of the default namespace and can be called directly using their names.
from numpy import *
x = array([1, 2, 3, 4, 5])
print x
[1 2 3 4 5] 
Importing selected functions from a module into the default namespace. This will import only the selected functions from the module.
from numpy import array
x = array([1, 2, 3, 4, 5])
print x
[1 2 3 4 5]
The method you prefer is usually a matter of choice and may depend to some extent on the context under which you are using Python. Importing everything into the default namespace is may be a good idea while using Python interactively in a shell but is not a good idea when writing Python scripts.
Creating NumPy Arrays
In the following description, it is assumed that NumPy has been imported into the default namespace, merely to save some typing.
Onedimensioned Arrays
Let us create a onedimensioned array x and study its properties:
x = array([1, 2, 3, 4, 5])
print type(x)
<type 'numpy.ndarray'>
print type(x[0])
<type 'numpy.int32'>
print ndim(x)
1
print x.shape
(5L,)
print len(x)
5
print size(x)
5
We can observe the following points:
 the NumPy function array() creates a ndimensioned array numpy.ndarray, which is stored in the variable x.
 Each element of the array x is of type numpy.int32
 Array x is onedimensioned and has 5 elements
 The shape attribute shows that x has only one dimension and the size along the first dimension is 5
 The array x has a total of 5 elements, as shown by the size() function
 The size along the first dimension is 5, as shown by the len() function
Twodimensioned Arrays
Observing the same attributes of a twodimensioned array gives an insight into how Python implements ndimensioned arrays.
y = array([ [1, 2, 3, 4], [5,6, 7, 8] ])
print type(y)
<type 'numpy.ndarray'>
print type(y[0, 0])
<type 'numpy.int32'>
print ndim(y)
2
print y.shape
(2L, 4L)
print len(y)
2
print size(y)
8
From the above, we can note the following points:
 Array y is of type numpy.ndarray and each element of y is of type numpy.int32
 Array y is twodimensioned
 Array y has size 2 along the first dimension and size 4 along the second dimension. We usually refer to the first dimension as rows and the second dimension as columns. Thus array y has 2 rows and 4 columns
 Array y has the size 2 along the first dimension, as shown by the len() function
 Array y has a total of 8 elements
Threedimensioned Arrays
We could similarly create threedimensioned or multidimensioned arrays and explore their properties. Here is an example of a threedimensioned array to close this discussion:
z = array([ [ [1, 2, 3, 4], [5,6, 7, 8], [9, 10, 11, 12] ],
[ [13, 14, 15,16], [17, 18,19, 20], [21, 22, 23, 24] ] ])
print z
[[[ 1 2 3 4]
[ 5 6 7 8]
[ 9 10 11 12]
[13 14 15 16]
[17 18 19 20]
[21 22 23 24]]]
print type(z)
<type 'numpy.ndarray'>
print type(z[0, 0, 0])
<type 'numpy.int32'>
print ndim(z)
3
print z.shape
(2L, 3L, 4L)
print len(z)
2
print size(z)
24
The output above must be self explanatory.