Book Image

Learning SciPy for Numerical and Scientific Computing Second Edition

Book Image

Learning SciPy for Numerical and Scientific Computing Second Edition

Overview of this book

Table of Contents (15 chapters)
Learning SciPy for Numerical and Scientific Computing Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Vector operations


In addition to being mathematical entities studied in linear algebra, Vectors are widely used in physics and engineering as a convenient way to represent physical quantities as displacement, velocity, acceleration, force, and so on. Accordingly, basic operations between vectors can be performed via Numpy/SciPy operations as follows:

Addition/subtraction

Addition/subtraction of vectors does not require any explicit loop to perform them. Let's take a look at addition of two vectors:

>>> vectorC = vectorA + vectorB
>>> vectorC

The output is shown as follows:

array([8, 8, 8, 8, 8, 8, 8])

Further, we perform subtraction on two vectors:

>>> vectorD = vectorB - vectorA
>>> vectorD

The output is shown as follows:

array([ 6,  4,  2,  0, -2, -4, -6])

Scalar/Dot product

Numpy has the built-in function dot to compute the scalar (dot) product between two vectors. We show you its use computing the dot product of vectorA and vectorB from the previous code...