02.04 - NumPy Exercises

Exercises rating:

★☆☆ - You should be able to do it based on Python knowledge plus the text.

★★☆ - You will need to do extra thinking and some extra reading/searching.

★★★ - The answer is difficult to find by a simple search, requires you to do a considerable amount of extra work by yourself (feel free to ignore these exercises if you're short on time).

1. Import the numpy package under the name np (★☆☆)

In [ ]:
 

2. Print the numpy version and the configuration (★☆☆)

In [ ]:
 

3. Create a null vector of size 10 (★☆☆)

In [ ]:
 

4. Create a vector with values ranging from 10 to 49 (★☆☆)

In [ ]:
 

5. Create a 3x3 matrix with values ranging from 0 to 8 (★☆☆)

In [ ]:
 

6. Create a 3x3x3 array with random values (★☆☆)

In [ ]:
 

7. Sort the columns of the following array (★☆☆)

In [ ]:
x = np.array([[3, 7],
              [7, 3],
              [1, 2]])

8. Select the 3rd, 4th and 7th column of the following array (★★☆)

In [ ]:
x = np.arange(32).reshape(4, 8)

9. Use argsort to sort the following array (★★☆)

In [ ]:
x = np.array([2, 7, 42, 27, 6, 9, 12])

10. Retrieve all positive values smaller than 7 (★★☆)

In [ ]:
x = np.arange(-6, 58, 2).reshape(4, 8)

11. In a single operation add 2 to all odd columns and 7 to all even columns (★★☆)

In [ ]:
x = np.arange(32).reshape(4, 8)