Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning SciPy for Numerical and Scientific Computing Second Edition

You're reading from  Learning SciPy for Numerical and Scientific Computing Second Edition

Product type Book
Published in Feb 2015
Publisher Packt
ISBN-13 9781783987702
Pages 188 pages
Edition 1st Edition
Languages

Vector creation


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 remain...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}