Exercises 1
Exercises 1
Put all your exercises (Jupyter Notebooks or Python-files) in your course Git-project.
Use either code comments or Jupyter Notebook markdown (text) to document which
exercise you are doing and what a certain code section does!
You can return all of these exercises in a single Jupyter Notebook, if you wish.
Tip: creating a list with Python code is usually something like this:
numbers = []
for x in range(0, 5):
numbers.append(x)
Note: compare the NumPy code to the plain Python code after doing the
exercises. Easier or more difficult? (answer in code comments or as text
in Jupyter Notebook)
3. Let's try out NumPy vectors and matrices:
• Create a NumPy vector (list) containing these values:
5, 16, 9, 2, 19, 18, 11, 7
• Use argmax() to find the position index of the largest value in
the vector, and print it
Note: The values above have no logic, you'll have to feed basic
Python lists to NumPy for this result
• Create a slice of the matrix that contains this part of the matrix:
• Extra task: Do the total sum, row sum and column sum exercises
without NumPy in Python!
Note: Don't create a new dataset when adding 50 to all values in the array,
use the existing one.
Advanced tasks (varying challenges, some require Googling):
This is useful if you have two separate arrays, but their data should
be in sync even if order of data is changed. For example, one array
contains the prices of cars, and another contains the manufacturing
years. If we wish to sort the data by manufacturing years, and keep
the prices in sync as well, argsort will be handy.
Useful link:
http://arogozhnikov.github.io/2015/09/29/NumpyTipsAndTricks1.ht
ml
You can write your thoughts as comments in the code as you try out
each feature.
o np.repeat()
o np.ravel()
o np.hsplit(), np.vsplit(), np.hstack, np.vstack()
o np.transpose()
o np.round()
o np.expand_dims(), np.squeeze()
o np.digitize()