Skip to main content

Fast Python: NumPy and Cython

  • Chapter
  • First Online:
  • 1665 Accesses

Part of the book series: Lecture Notes in Earth System Sciences ((LNESS))

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

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   79.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   99.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD   139.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Gabriele Morra .

Rights and permissions

Reprints 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

Publish with us

Policies and ethics