From your shell, *cd* to your python workspace/folder and type:
This command will launch Ipython with the pylab option on. This option will provide an interactive environment, to generate plots.
Importing libraries permits to extend python default functionality by calling exterior code packages. There are several ways to import libraries in python with different implications. In this tutorial, two different import statements will be use.
Let us import a very useful library, numpy. numpy has very similar capability to matlab and is therefore widely use in the scientific community.
import numpy as np
Here the entire package has been imported and renamed np. This format of import format is good-practise since it allows to keep track of the package and their attached functions and avoid confusions. for example:
np.round
<function numpy.core.fromnumeric.round_>
is different from:
round
<function round>
Here is a non-exhaustive list of useful shortcuts available in Ipython:
Tab: Tab completion, especially for attributes, is a convenient way to explore the structure of any object you’re dealing with. Simply type *object_name.Tab* to view the object’s attributes (see the readline section for more). Besides Python objects and keywords, tab completion also works on file and directory names.
Up & down arrows: IPython stores both the commands you enter, and the results it produces. You can easily go through previous commands with the up- and down-arrow keys, or access your history in more sophisticated ways. One can also use up- and down-arrow keys for auto-completion purposes based on one's command history.
?: ? permits a quick access to the documentation of any object or function. Typing *object_name?* will unravel the documentation related to the object. Sometimes, one has to type *q* to quit the documentation.
Despite their capability similitudes, there are few major differences between numpy and matlab. Here follows probably the most important ones:
N = 10
M = np.ones((N)) #define a 1D array of N elements
print "Shape of M: ", M.shape
print "First element= ", M[0]
print "Last element= ", M[9]
Shape of M: (10,) First element= 1.0 Last element= 1.0
Fortunately, numpy and matlab have more similitudes than differences, so much that matlab users will rapidly make their heads around numpy
PEP stands for Python Enhancement Proposals. They are Best-practises type documents for Python programming. It is recommended to follow as much as possible PEP 20, PEP 8 and PEP 257 (i.e.http://legacy.python.org/dev/peps/)