Python loops over large array structures are known to run slowly. Tests with class Grid2D from Chapter 4.3.5 show that filling a two-dimensional array of size 1100 × 1100 with nested loops in Python may require about 150 times longer execution time than using Fortran 77 for the same purpose. With Numerical Python (NumPy) and vectorized expressions (from Chapter 4.2) one can speed up the code by a factor of about 50, which gives decent performance.
There are cases where vectorization in terms of NumPy functions is demanding or inconvenient: it would be a lot easier to just write straight loops over array structures in Fortran, C, or C++. This is quite easy, and the details of doing this in F77 are explained in the present chapter. Chapter 10 covers the same material in a C and C++ context.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2009 Springer-Verlag Berlin Heidelberg
About this chapter
Cite this chapter
(2009). Fortran Programming with NumPy Arrays. In: Langtangen, H.P. (eds) Python Scripting for Computational Science. Texts in Computational Science and Engineering, vol 3. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-540-73916-6_9
Download citation
DOI: https://doi.org/10.1007/978-3-540-73916-6_9
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-73915-9
Online ISBN: 978-3-540-73916-6
eBook Packages: Mathematics and StatisticsMathematics and Statistics (R0)