807 B
Exercise 3 Slicing
The goal of this exercise is to learn NumPy indexing/slicing. It allows to access values of the NumPy array efficiently and without a for loop.
-
Create a NumPy array of dimension 1 that contains all integers from 1 to 100 ordered.
-
Without using a for loop and using the array created in Q1, create an array that contain all odd integers. The expected output is:
np.array([1,3,...,99])
. Hint: it takes one line -
Without using a for loop and using the array created in Q1, create an array that contain all even integers reversed. The expected output is:
np.array([100,98,...,2])
. Hint: it takes one line -
Using array of Q1, set the value of every 3 elements of the list (starting with the second) to 0. The expected output is:
np.array([[1,0,3,4,0,...,0,99,100]])