For the impatient, here is how to use arrays in a nutshell. Be aware though that the behavior of arrays may be surprising at first, so we encourage you to read on after this introductory section.
Creating vectors is as simple as using the function array
to convert a list to an array:
v = array([1.,2.,3.])
The object v
is now a vector that behaves much like a vector in linear algebra. We have already emphasized the differences with the list object in Python (refer to section Arrays in Chapter 3, Containers Type). Here are some illustrations of the basic linear algebra operations on vectors:
# two vectors with three components v1 = array([1., 2., 3.]) v2 = array([2, 0, 1.]) # scalar multiplications/divisions 2*v1 # array([2., 4., 6.]) v1/2 # array([0.5, 1., 1.5]) # linear combinations 3*v1 # array([ 3., 6., 9.]) 3*v1 + 2*v2 # array([ 7., 6., 11.]) # norm from scipy.linalg import...