Book Image

Scientific Computing with Python 3

By : Claus Führer, Jan Erik Solem, Olivier Verdier
Book Image

Scientific Computing with Python 3

By: Claus Führer, Jan Erik Solem, Olivier Verdier

Overview of this book

Python can be used for more than just general-purpose programming. It is a free, open source language and environment that has tremendous potential for use within the domain of scientific computing. This book presents Python in tight connection with mathematical applications and demonstrates how to use various concepts in Python for computing purposes, including examples with the latest version of Python 3. Python is an effective tool to use when coupling scientific computing and mathematics and this book will teach you how to use it for linear algebra, arrays, plotting, iterating, functions, polynomials, and much more.
Table of Contents (23 chapters)
Scientific Computing with Python 3
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Acknowledgement
Preface
References

Lists


A list is, as the name hints, a list of objects of any kind:

L = ['a' 20.0, 5]
M = [3,['a', -3.0, 5]]

The individual objects are enumerated by assigning each element an index. The first element in the list gets index 0. This zero-based indexing is frequently used in mathematical notation. Consider the usual indexing of coefficients of a polynomial.

The index allows us to access the following objects:

L[1] # returns 20.0
L[0] # returns 'a'
M[1] # returns ['a',-3.0,5]
M[1][2] # returns 5

The bracket notation here corresponds to the use of subscripts in mathematical formulas. L is a simple list, while M itself contains a list so that one needs two indexes to access an element of the inner list.

A list containing subsequent integers can easily be generated by the command range:

L=list(range(4)) # generates a list with four elements: [0, 1, 2 ,3]

A more general use is to provide this command with start, stop, and step parameters:

L=list(range(17,29,4)) # generates [17, 21, 25...