Skip main navigation

Hands-on: Random numbers

In this exercise we practice creating arrays of random numbers. Source code for this exercise is located in numpy/random-numbers/ Generate a one dimensional 1000 element array of uniformly distributed randomnumbers …

Hands-on: Input and output

In this exercise we study how to read and write arrays to disk. Source code for this exercise is located in numpy/input-output/ File numpy/input-output/xy-coordinates.dat contains a list of (x,y) valuepairs. …

File I/O

NumPy provides functions for reading and writing numeric data to simple files in a regular column layout. These I/O functions offer a very convenient way to load and store data …

Hands-on: Translation with broadcasting

In this exercise we study NumPy broadcasting, which is powerful tool for dealing with different, but compatible shape arrays. Source code for this exercise is located in numpy/broadcast-translation/ File numpy/broadcast-translation/points_circle.dat …

Hands-on: Split and combine arrays

In this exercise you can learn how to split and combine NumPy arrays. Source code for this exercise is located in numpy/split-combine/ Create a new 8×8 array with some values …

Array manipulation and broadcasting

When working with NumPy arrays it is sometimes necessary to manipulate the shape and/or size of them. One can for example modify the shape of an array as well as …

Hands-on: Numerical integration

We continue studying vectorized operations with numerical integration. Source code for this exercise is located in numpy/integration/ A simple method for evaluating integrals numerically is by the middle Riemannsum [S …

Hands-on: Finite difference

In this exercise we study vectorization, which is crucial for obtaining good performance with NumPy. Source code for this exercise is located in numpy/finite-difference/ Derivatives can be calculated numerically with …

Arithmetics and elementary functions

Element-wise operations Simple calculations are very straightforward with NumPy arrays. Basic arithmetic operations (+ - * / **) can all be used with arrays. The mainthing to keep in mind …

Hands-on: Array slicing

In this exercise we explore the slicing syntax of NumPy arrays. Source code for this exercise is located in numpy/array-slicing/ First, create a 4×4 array with arbitrary values, then Extract …

Vectorised operations

For loops in Python are slow. If one needs to apply a mathematical operation on multiple (consecutive) elements of an array, it is always better to use a vectorised operation …

Hands-on: Array creation

In this exercise we explore various ways of creating NumPy arrays Source code for this exercise is located in numpy/array-creation/ Start from a Python list containing both integers and floating …

Creating and accessing NumPy arrays

NumPy arrays have a fixed number of elements and all the elements have the same datatype, both specified when creating the array. Even though the number of elements is fixed, …

Week 1 summary

We hope that you have enjoyed the first week of Python in High Performance Computing! This week, we have discussed various performance challenges in Python programs and have set up …