Presentation is loading. Please wait.

Presentation is loading. Please wait.

Python Scripting for Computational Science CPS 5401 Fall 2014 Shirley Moore, Instructor October 6,

Similar presentations


Presentation on theme: "Python Scripting for Computational Science CPS 5401 Fall 2014 Shirley Moore, Instructor October 6,"— Presentation transcript:

1 Python Scripting for Computational Science CPS 5401 Fall 2014 Shirley Moore, Instructor October 6, 2014 1

2 Scripting vs. Traditional Programming Traditional programming builds large applications using Fortran, C, C++, Java, etc. Scripting means programming at a higher abstraction level in more flexible languages such as Python, Perl, Ruby, Tcl. Scripting often serves to integrate programs written in traditional languages – for example, to integration simulation and visualization Scripting can allow you to build your own Matlab-like scientific computing environment. Scripting can help build demos for teaching or project presentations. Can use scripting to run and collect results from experiments. 2

3 Python vs. Matlab Python is more powerful. Python environment is completely open and designed for integration with external tools. Nested, heterogeneous data structures are easy to construct and use in Python. Interfacing to C, C++, and Fortran is better supported in Python. Matlab is a self-contained well-supported environment. pymat interface allows Python programs to use Matlab as a computational and graphics engine. 3

4 NumPy Package for scientific computing with Python Powerful N-dimensional array objects Allows definition of arbitrary data types Tools for integrating C/C++ and Fortran code Linear algebra, Fourier transform, and random number capabilities 4

5 NumPy Example 5

6 Creating Arrays Create from Python list using the array function: 6

7 Creating Arrays (2) Can create with placeholder content: 7

8 Creating Arrays (3) NumPy arange function analogous to Python range function but returns array instead of list linspace better for floating point numbers: 8

9 Arithmetic Operations Arithmetic operations on arrays are applied elementwise. New array is created to hold the result. 9

10 Arithmetic Operations (2) 10

11 Arithmetic Operations (3) In-place operators modify existing array rather than creating new one. 11

12 Unary Operations 12

13 Apply Operation along an Axis 13

14 Array Slicing 14

15 Shape Manipulation 15

16 Stacking Arrays 16

17 Splitting Arrays 17

18 Linear Algebra 18

19 Linear Algebra (2) 19

20 Matrix Class 20

21 Histograms 21

22 SciPy http://www.scipy.org/ Library for scientific computing in Python Depends on NumPy for 2d arrays and some operations Some overlap with NumPy Better to use scipy.linalg than numpy.linalg SciPy tutorial – http://docs.scipy.org/doc/scipy/reference/tutorial /index.html http://docs.scipy.org/doc/scipy/reference/tutorial /index.html 22


Download ppt "Python Scripting for Computational Science CPS 5401 Fall 2014 Shirley Moore, Instructor October 6,"

Similar presentations


Ads by Google