You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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.

  1. Create a NumPy array of dimension 1 that contains all integers from 1 to 100 ordered.

  2. 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

  3. 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

  4. 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]])