Akanksha

Posted on

# Top 30 NumPy Interview Questions with Answers multiple choice style

### 1. What is NumPy?

A. A deep learning framework
B. A scientific computing library
C. A web development framework
D. An operating system
Answer: B. A scientific computing library

### 2. Which of the following data structures is not provided by NumPy?

A. Array
B. List
C. Matrix
D. Multi-dimensional array

### 3. What is the primary data structure in NumPy?

A. List
B. Tuple
C. N-dimensional array
D. Dictionary

### 4. Which of the following is the correct way to import NumPy in Python?

A. import numpy
B. import np
C. import numpy as np
D. from numpy import *
Answer: C. import numpy as np

A. int8
B. int16
C. int32
D. int64

### 6. How can you create a NumPy array with all elements initialized to zero?

A. np.zeros(0)
B. np.zeros((1, 1))
C. np.zeros(5, 5)
D. np.zeros((5, 5))

### 7. What does the NumPy shape attribute return for a given array?

A. Number of elements in the array
B. Number of dimensions in the array
C. Size of the array
D. Tuple of array dimensions
Answer: D. Tuple of array dimensions

A. linspace()
B. arange()
C. sequence()
D. range()

A. a + b
D. np.sum(a, b)

### 10. What does the NumPy function np.dot(a, b) perform?

A. Element-wise multiplication of a and b
B. Matrix multiplication of a and b
C. Dot product of a and b
D. Finding the determinant of a
Answer: B. Matrix multiplication of a and b

### 11. How can you transpose a NumPy array arr?

A. arr.transpose()
B. np.transpose(arr)
C. arr.T
D. All of the above
Answer: D. All of the above

### 12. What is the purpose of the NumPy function np.reshape()?

A. To change the number of elements in the array
B. To change the shape of the array
C. To convert the array to a list
D. To sort the elements in the array
Answer: B. To change the shape of the array

### 13. Which of the following functions is used to find the maximum value in a NumPy array arr?

A. arr.max()
B. np.max(arr)
C. max(arr)
D. np.maximum(arr)

### 14. What is the purpose of the NumPy function np.argmax()?

A. It returns the maximum value in an array.
B. It returns the index of the maximum value in an array.
C. It computes the dot product of two arrays.
D. It reshapes an array.
Answer: B. It returns the index of the maximum value in an array.

### 15. How can you concatenate two NumPy arrays vertically?

A. np.stack((arr1, arr2), axis=0)
B. np.vstack((arr1, arr2))
C. np.concat((arr1, arr2), axis=0)
D. np.append(arr1, arr2, axis=0)

### 16. What is the function np.where(condition, x, y) used for?

A. It computes the dot product of x and y.
B. It returns the indices where condition is True, and x where condition is False.
C. It returns the maximum value of x and y.
D. It reshapes the array x to match the shape of y.
Answer: B. It returns the indices where condition is True, and x where condition is False.

### 17. How can you perform element-wise subtraction of two NumPy arrays a and b?

A. np.subtract(a, b)
B. a - b
C. np.minus(a, b)
D. a.subtract(b)

### 18. What is the purpose of the NumPy function np.mean()?

A. It computes the dot product of two arrays.
B. It returns the mean (average) value of an array.
C. It computes the maximum value of an array.
D. It reshapes the array.
Answer: B. It returns the mean (average) value of an array.

A. np.stdev()
B. np.std()
C. np.variance()
D. np.mean()

### 20. What is the purpose of the NumPy function np.median()?

A. It computes the dot product of two arrays.
B. It returns the median value of an array.
C. It computes the minimum value of an array.
D. It reshapes the array.
Answer: B. It returns the median value of an array.

### 21. How can you find the unique values in a NumPy array arr?

A. np.unique(arr)
B. arr.distinct()
C. np.distinct(arr)
D. arr.unique()

### 22. What does the NumPy function np.save() do?

A. It computes the sum of all elements in an array.
B. It saves an array to a binary file on disk.
C. It converts an array to a list.
D. It sorts the elements in an array.
Answer: B. It saves an array to a binary file on disk.

A. np.exp()
B. np.power()
C. np.exponent()
D. np.elevate()

### 24. How can you calculate the absolute values of the elements in a NumPy array arr?

A. np.abs(arr)
B. arr.absolute()
C. np.absolute(arr)
D. abs(arr)

A. np.round()
B. np.floor()
C. np.ceil()
D. np.trunc()

### 26. How can you calculate the element-wise square root of a NumPy array arr?

A. np.sqrt(arr)
B. arr.square_root()
C. np.square_root(arr)
D. sqrt(arr)

### 27. What does the NumPy function np.linspace(1, 10, 5) do?

A. Creates an array with elements from 1 to 10, with 5 elements in total.
B. Computes the dot product of two arrays.
C. Rounds the elements of an array to the nearest integer.
D. Reshapes an array.
Answer: A. Creates an array with elements from 1 to 10, with 5 elements in total.

### 28. How do you perform element-wise multiplication of two NumPy arrays a and b?

A. np.multiply(a, b)
B. a * b
C. np.mult(a, b)
D. a.multiply(b)

### 29. What is the function of the NumPy function np.random.rand(3, 3)?

A. Creates an array with random elements between 0 and 1.
B. Generates a random integer.
C. Computes the dot product of two arrays.
D. Rounds the elements of an array to the nearest integer.
Answer: A. Creates an array with random elements between 0 and 1.

A. np.log()
B. np.natlog()
C. np.ln()
D. np.exp()