Skip main navigation

Hands-on: Translation with broadcasting

Translate coordinates using broadcasting.
© CC-BY-NC-SA 4.0 by CSC - IT Center for Science

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')
plt.show()
© CC-BY-NC-SA 4.0 by CSC - IT Center for Science
This article is from the free online

Python in High Performance Computing

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now