DS Utilities: Numpy
TD; DR
In this Chapter, take the following 25 exercises to learn how to use the basic APIs of numpy
.
Exercise on Numpy
1. Import the numpy package under the name np
np
2. Create a null vector of size 10
3. Create a null vector of size 10 but the fifth value which is 1
4. Create a vector with values ranging from 10 to 49
5. Reverse a vector (first element becomes last)
Also tries:
6. Create a 3x3 matrix with values ranging from 0 to 8
7. Find indices of non-zero elements from [1,2,0,0,4,0]
[1,2,0,0,4,0]
8. Create a 3x3 identity matrix
Identity matrix: values on positive diagnosis of matrix are 1, and others are 0
Also recognized as I_n
9. Create a 3x3x3 array with random values
10. Create a 10x10 array with random values and find the minimum and maximum values
11. Create a random vector of size 30 and find the mean value
12. Create a 2d array with 1 on the border and 0 inside
13. How to add a border (filled with 0's) around an existing array?
14. Create a 5x5 matrix with values 0,1,2,3,4 on the diagonal
15. Create a 8x8 matrix and fill it with a chess board pattern
Chess board Pattern is just like:
16. Consider a (6,7,8) shape array, what is the index (x,y,z) of the 100th element?
17. Matrix Addition and Subtraction
Add up two matries A and B, where A and B respectively be:
18. Normalize a 5x5 random matrix
Normalize a matrix(归一化矩阵) is to make every values in the matrix lies on [min, max], as an example: we have an array valued [-1, 1, 3]. After normalization, it becomes [0, 0.5, 1].
19. Multiply a 5x3 matrix by a 3x2 matrix (real matrix product)
20. Given a 1D array, negate all elements which are between 3 and 8, in place.
21. How to find common values between two arrays?
22. How to get the dates of yesterday, today and tomorrow?
23. Create a vector of size 6 with values in equal spacing ranges [0, 20]
24. Create a random vector of size 10 and sort it
25. Create random vector of size 10 and replace the maximum value by 0
What is the relationship between
Z.argmax()
andZ.max()
?
Last updated