2.7 KiB
2.7 KiB
In this exercise, we'll do calculations on many numbers at once. Python provides the numpy library for that.
In [ ]:
# !pip install numpy
In [ ]:
import numpy as np %matplotlib notebook from matplotlib import pyplot
Exercise: Use np.arange(..., ...)
to create a vector from 0
up to and including 5
.
In [ ]:
x = None print('x: ', x)
Exercise: Extract 1
from all the numbers
In [ ]:
y = None print('y: ', y)
Exercise: Take the square root of all these numbers, either using ** 0.5
or np.sqrt( ... )
In [ ]:
y = None print('y: ', y)
Notice that the square root of -1
is not defined, and hence the result is not a number (nan).
The cell below will make a plot of x
and y
.
In [ ]:
pyplot.plot(x, y) pyplot.xlabel('x') pyplot.ylabel('y') None
You have learned to use numpy
for so called vector operations, these are mathematical operations on many numbers as well. This field is called linear algebra, and is a usefull field on its own, in particular often used in artificial intelligence.