First page Back Continue Last page Overview Graphics

Lists in darrays

We have a list with values, e.g. temperatures in Celsius:

>>> cvalues = [25.3, 24.8, 26.9, 23.9]

We turn this into a one-dimensional numpy array:

>>> C = np.array(cvalues)

>>> print(C)

[ 25.3 24.8 26.9 23.9]

We can easily turn the values of this darray into degrees Fahrenheit.

This can be achieved by simple scalar multiplication:

>>> print(C * 9 / 5 + 32)

[ 77.54 76.64 80.42 75.02]

Compared to this, a solution using a Python list is extremely awkward:

>>> fvalues = [ x*9/5 + 32 for x in cvalues] print(fvalues)[77.54, 76.64, 80.42, 75.02]