Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Cython Programming (Second Edition)

You're reading from   Learning Cython Programming (Second Edition) Expand your existing legacy applications in C using Python

Arrow left icon
Product type Paperback
Published in Feb 2016
Publisher Packt
ISBN-13 9781783551675
Length 110 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Philip Herron Philip Herron
Author Profile Icon Philip Herron
Philip Herron
Arrow right icon
View More author details
Toc

Cython and NumPy


NumPy is a scientific library designed to provide functionality similar to or on par with MATLAB, which is a paid proprietary mathematics package. NumPy has a lot of popularity with Cython users since you can seek out more performance from your highly computational code using C types. In Cython, you can import this library as follows:

import numpy as np
cimport numpy as np

np.import_array()

You can access full Python APIs as follows:

np.PyArray_ITER_NOTDONE

So, you can integrate with iterators at a very native area of the API. This allows NumPy users to get a lot of speed when working with native types via something as follows:

cdef double * val = (<double*>np.PyArray_MultiIter_DATA(it, 0))[0]

We can cast the data from the array to double, and it's a cdef type in Cython to work with now. For more information and NumPy tutorials, visit https://github.com/cython/cython/wiki/tutorials-numpy.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image