Want to keep learning?

This content is taken from the Partnership for Advanced Computing in Europe (PRACE)'s online course, Python in High Performance Computing. Join the course to learn more.

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 contains x, y coordinates along a circle. Translate all the coordinates with some vector e.g. (2.1, 1.1). Plot both the original and translated points in order to see the effect of the translation.

In case you are not familiar with matplotlib, below is a simple example for plotting coordinates:

import numpy as np
import matplotlib.pyplot as plt

x = np.random.random(10)
y = np.random.random(10)
plt.plot(x, y, 'o')

Share this article:

This article is from the free online course:

Python in High Performance Computing

Partnership for Advanced Computing in Europe (PRACE)