Abstract
Python can combine simplicity with speed in a unique way, but much care has to be paid in avoiding bottlenecks, particularly avoiding unnecessary loops and heavily using its vectorized functions. In this chapter I make a detailed overview of the types of Python, how to speedup calculations with array, how to efficiently select subsets of large arrays. By illustrating strides, I explain how Numerical Python can achieve its performance and how to benchmark them. Finally, I illustrate how to add vector and linear algebra calculations to an applied modeling software and eventually use Cython, the C extension to Python, to add special functions that cannot be performed using the vectorized NumPy library.
“Give me 6 hours to chop a tree, I will spend the first 4 sharpening my axe.” —Abe Lincoln
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsPreview
Unable to display preview. Download preview PDF.
Author information
Authors and Affiliations
Corresponding author
Rights and permissions
Copyright information
© 2018 Springer International Publishing AG
About this chapter
Cite this chapter
Morra, G. (2018). Fast Python: NumPy and Cython. In: Pythonic Geodynamics. Lecture Notes in Earth System Sciences. Springer, Cham. https://doi.org/10.1007/978-3-319-55682-6_3
Download citation
DOI: https://doi.org/10.1007/978-3-319-55682-6_3
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-55680-2
Online ISBN: 978-3-319-55682-6
eBook Packages: Earth and Environmental ScienceEarth and Environmental Science (R0)