Interview Questions and Answers
Freshers / Beginner level questions & answers
Ques 1. What is NumPy?
NumPy is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with mathematical functions to operate on these arrays.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 2. How to install NumPy?
You can install NumPy using the command 'pip install numpy'.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 3. Create a NumPy array from a Python list.
import numpy as npnmy_list = [1, 2, 3]narr = np.array(my_list)
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 4. How to find the dimension of a NumPy array?
You can use the attribute 'ndim'. For example, if 'arr' is your array, use 'arr.ndim'.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 5. What is the difference between 'np.zeros()' and 'np.ones()' in NumPy?
'np.zeros()' creates an array filled with zeros, while 'np.ones()' creates an array filled with ones.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 6. How to access elements from a 2D NumPy array?
You can use indices. For example, 'arr[1, 2]' accesses the element in the second row and third column of 'arr'.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 7. How to find the shape of a NumPy array?
You can use the attribute 'shape'. For example, 'arr.shape' returns the shape of 'arr'.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 8. What is the purpose of 'np.eye()' in NumPy?
'np.eye()' creates an identity matrix with ones on the main diagonal and zeros elsewhere.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 9. How to perform element-wise addition of two NumPy arrays?
import numpy as npnarr1 = np.array([1, 2, 3])narr2 = np.array([4, 5, 6])nresult = arr1 + arr2
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 10. What is the purpose of 'np.arange()' in NumPy?
'np.arange()' creates an array with regularly spaced values within a specified range.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 11. How to find the mean of a NumPy array?
You can use 'np.mean()'. For example, 'mean_value = np.mean(arr)'.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Intermediate / 1 to 5 years experienced level questions & answers
Ques 12. Explain broadcasting in NumPy.
Broadcasting is a powerful mechanism that allows NumPy to work with arrays of different shapes when performing arithmetic operations.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 13. How to perform element-wise multiplication of two NumPy arrays?
import numpy as npnarr1 = np.array([1, 2, 3])narr2 = np.array([4, 5, 6])nresult = arr1 * arr2
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 14. Explain the purpose of np.random.seed() in NumPy.
np.random.seed() is used to initialize the random number generator in NumPy, ensuring reproducibility of random results.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 15. Explain the concept of a NumPy universal function (ufunc).
A ufunc in NumPy is a flexible function that operates element-wise on NumPy arrays, supporting broadcasting.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 16. How to concatenate two NumPy arrays vertically?
You can use 'np.vstack()' or 'np.concatenate()' with 'axis=0'.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 17. What is the purpose of 'np.ravel()' in NumPy?
'np.ravel()' returns a flattened 1D array from a multi-dimensional array.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 18. Explain the purpose of 'np.concatenate()' in NumPy.
'np.concatenate()' joins a sequence of arrays along an existing axis.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 19. How to perform matrix multiplication in NumPy?
You can use 'np.matmul()' or the '@' operator. For example, 'result = np.matmul(arr1, arr2)' or 'result = arr1 @ arr2'.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Experienced / Expert level questions & answers
Ques 20. What is the purpose of np.newaxis in NumPy?
np.newaxis is used to increase the dimension of the existing array by one more dimension when used once.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 21. Explain the differences between np.dot() and np.matmul() in NumPy.
np.dot() performs matrix multiplication for 2-D arrays, while np.matmul() is equivalent to the '@' operator and is more general.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 22. Create a diagonal matrix using NumPy.
import numpy as npnarr = np.diag([1, 2, 3])
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 23. Explain the purpose of np.meshgrid() in NumPy.
np.meshgrid() is used to create coordinate matrices from coordinate vectors, commonly used for 3D plotting.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 24. Explain the use of 'np.histogram()' in NumPy.
'np.histogram()' computes the histogram of a set of data, returning the bin counts and bin edges.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 25. How to find the index of the maximum value in a NumPy array?
You can use 'np.argmax()'. For example, 'np.argmax(arr)' returns the index of the maximum value in 'arr'.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 26. What is the purpose of 'np.where()' in NumPy?
'np.where()' returns the indices of elements that satisfy a given condition.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 27. Explain the use of 'np.linalg.inv()' in NumPy.
'np.linalg.inv()' computes the (multiplicative) inverse of a matrix.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 28. What is the purpose of 'np.percentile()' in NumPy?
'np.percentile()' calculates the nth percentile of a dataset.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 29. Explain the use of 'np.unique()' in NumPy.
'np.unique()' returns the unique elements of an array.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 30. How to transpose a NumPy array?
You can use 'arr.T'. For example, 'transposed_arr = arr.T'.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Most helpful rated by users:
- How to install NumPy?
- Create a NumPy array from a Python list.
- What is NumPy?
- What is the difference between 'np.zeros()' and 'np.ones()' in NumPy?
- What is the purpose of 'np.eye()' in NumPy?
Related interview subjects
| Pandas perguntas e respostas de entrevista - Total 30 questions |
| Deep Learning perguntas e respostas de entrevista - Total 29 questions |
| Flask perguntas e respostas de entrevista - Total 40 questions |
| PySpark perguntas e respostas de entrevista - Total 30 questions |
| PyTorch perguntas e respostas de entrevista - Total 25 questions |
| Data Science perguntas e respostas de entrevista - Total 23 questions |
| SciPy perguntas e respostas de entrevista - Total 30 questions |
| Generative AI perguntas e respostas de entrevista - Total 30 questions |
| NumPy perguntas e respostas de entrevista - Total 30 questions |
| Python perguntas e respostas de entrevista - Total 106 questions |
| Python Pandas perguntas e respostas de entrevista - Total 48 questions |
| Django perguntas e respostas de entrevista - Total 50 questions |
| Python Matplotlib perguntas e respostas de entrevista - Total 30 questions |