Skip to Main Content
Advanced Python Programming
book

Advanced Python Programming

by Dr. Gabriele Lanaro, Quan Nguyen, Sakis Kasampalis
February 2019
Intermediate to advanced content levelIntermediate to advanced
672 pages
16h 50m
English
Packt Publishing
Content preview from Advanced Python Programming

Running code on a GPU

In this subsection, we will demonstrate the usage of a GPU with Theano and Tensorflow. As an example, we will benchmark the execution of a very simple matrix multiplication on the GPU and compare it to its running time on a CPU.

The code in this subsection requires the possession of a GPU. For learning purposes, it is possible to use the Amazon EC2 service (https://aws.amazon.com/ec2) to request a GPU-enabled instance.

The following code performs a simple matrix multiplication using Theano. We use the T.matrix function to initialize a two-dimensional array, and then we use the T.dot method to perform the matrix multiplication:

    from theano import function, config    import theano.tensor as T    import numpy as np import time ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Python Programming - Second Edition

Advanced Python Programming - Second Edition

Quan Nguyen
Expert Python Programming - Third Edition

Expert Python Programming - Third Edition

Michał Jaworski, Tarek Ziadé, Cody Jackson
Python Workout

Python Workout

Reuven M. Lerner

Publisher Resources

ISBN: 9781838551216Supplemental Content