Numpy-Questions
December 2024
Practice Questions on NumPy
1. How do you create a NumPy array from a Python list?
2. What is the difference between np.array() and np.asarray()?
3. Demonstrate how to create a 3x3 identity matrix using NumPy.
4. How would you find the shape and size of a NumPy array?
5. Write code to generate a random array of shape (4, 5) with values between
0 and 1.
6. Explain how you would perform element-wise addition and multiplication
on two arrays.
7. What is the difference between np.zeros() and np.ones()?
8. How do you reshape a NumPy array without changing its data?
9. Demonstrate how to find the mean, median, and standard deviation of a
NumPy array.
10. Write code to extract all even numbers from a given NumPy array.
11. How do you stack two NumPy arrays vertically and horizontally?
12. Explain how you would perform slicing and indexing on a 2D NumPy
array.
13. How can you handle missing values in a NumPy array?
14. Write a code snippet to create a boolean mask for values greater than a
threshold in a NumPy array.
15. How do you compute the dot product of two matrices using NumPy?