NumPy 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.
Ques 2. How to install NumPy?
You can install NumPy using the command 'pip install numpy'.
Ques 3. Create a NumPy array from a Python list.
import numpy as npnmy_list = [1, 2, 3]narr = np.array(my_list)
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'.
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.
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'.
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'.
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.
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
Ques 10. What is the purpose of 'np.arange()' in NumPy?
'np.arange()' creates an array with regularly spaced values within a specified range.
Ques 11. How to find the mean of a NumPy array?
You can use 'np.mean()'. For example, 'mean_value = np.mean(arr)'.
Most helpful rated by users:
Related interview subjects
Python Pandas interview questions and answers - Total 48 questions |
Python Matplotlib interview questions and answers - Total 30 questions |
Django interview questions and answers - Total 50 questions |
Pandas interview questions and answers - Total 30 questions |
Deep Learning interview questions and answers - Total 29 questions |
PySpark interview questions and answers - Total 30 questions |
Flask interview questions and answers - Total 40 questions |
PyTorch interview questions and answers - Total 25 questions |
Data Science interview questions and answers - Total 23 questions |
SciPy interview questions and answers - Total 30 questions |
Generative AI interview questions and answers - Total 30 questions |
NumPy interview questions and answers - Total 30 questions |
Python interview questions and answers - Total 106 questions |