From the course: Faster pandas

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Writing Cython code

Writing Cython code

From the course: Faster pandas

Start my 1-month free trial

Writing Cython code

- [Lecturer] Let's convert some Python code to Cython. Here we have Python code in relu1.py. We define a function called relu, check if n is smaller than zero, and then we return zero. Otherwise, we return the original number. And now, to the Cython version. We start by directing, telling Cython we are using Python 3. And then, we have our function. And the only difference is that we specified that the type of the argument is doubled, which is sys equivalent of Python's float. This is not strictly necessary, but will help with performance. And the rest of the code is the same. And this file is called relu.pyx.

Contents