-
Book Overview & Buying
-
Table Of Contents
Learning SciPy for Numerical and Scientific Computing Second Edition - Second Edition
As mentioned in Chapter 2, Working with the NumPy Array As a First Step to SciPy, SciPy depends on NumPy's main object's ndarray data structure. You can look at one-dimensional arrays as vectors and vice versa (oriented points in an n-dimensional space). Consequently, a vector can be created via Numpy as follows:
>>> import numpy >>> vectorA = numpy.array([1,2,3,4,5,6,7]) >>> vectorA
The output is shown as follows:
array([1, 2, 3, 4, 5, 6, 7])
We can also use already defined arrays to create a new candidate. Some examples were presented in the previous chapter. Here we can reverse the already created vector and assign it to a new one:
>>> vectorB = vectorA[::-1].copy() >>> vectorB
The output is shown as follows:
array([7, 6, 5, 4, 3, 2, 1])
Notice that in this example, we have to make a copy of the reverse of the elements of vectorA and assign it to vectorB. This way, by changing elements of vectorB, the elements of vectorA...
Change the font size
Change margin width
Change background colour