O'Reilly logo

NumPy Cookbook - Second Edition by Ivan Idris

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 9. Speeding Up Code with Cython

In this chapter, we will cover the following recipes:

  • Installing Cython
  • Building a Hello World program
  • Using Cython with NumPy
  • Calling C functions
  • Profiling the Cython code
  • Approximating factorials with Cython

Introduction

Cython is a relatively young programming language based on Python. It allows coders to mix the speed of C with the power of Python. The difference with Python is that we can optionally declare static types. Many programming languages, such as C, have static typing, which means that we have to tell C the type of variables, function parameters, and return value types. Another difference is that C is a compiled language, while Python is an interpreted language. As a rule of thumb, we can say that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required