NumPy MCQs and Answers with Explanation | NumPy Quiz

NumPy MCQ's
Join Telegram Join Telegram
Join Whatsapp Groups Join Whatsapp

NumPy MCQs and Answers with Explanation: Please take a look at this article on the Quiz on NumPy to assess your knowledge about NumPy. Additionally, this article also gives a concise introduction to NumPy and the Top 25 NumPy Multiple Choice Questions. NumPy is a commonly used Python library for numerical computing. It offers a high-performance multidimensional array object and tools for manipulating these arrays. NumPy is designed to be efficient, flexible, and user-friendly, making it an essential tool for scientific computing, data analysis, and machine learning.

NumPy MCQs and Answers

NumPy’s array object is the cornerstone of the library, providing a powerful data structure for representing and manipulating numerical data. It supports a wide range of operations on arrays, including arithmetic operations, slicing and indexing, and broadcasting. NumPy also includes a large collection of mathematical functions, from basic operations like trigonometric functions to more advanced functions like Fourier transforms and linear algebra operations. This NumPy Online Quiz/ NumPy Quiz, in its question and format, will be of great assistance to candidates who need preparation for their interview or placement exams.

NumPy Multiple Choice Questions

Name NumPy
Exam Type MCQ (Multiple Choice Questions)
Category Technical Quiz
Mode of Quiz Online

Top 25 NumPy NumPy MCQ Questions & Answers | NumPy Online Quiz

1. What does NumPy stand for?

a) Numerical Python
b) Natural Python
c) Numeric Program
d) Nonlinear Python

Answer: a) Numerical Python

Explanation: NumPy stands for Numerical Python, which is a library in Python used for performing various mathematical operations and data manipulations efficiently.

2. What is the default data type of NumPy arrays?

a) int32
b) float64
c) object
d) None of the above

Answer: b) float64

Explanation: The default data type of NumPy arrays is float6d) However, it can be changed using the dtype parameter while creating the array.

3. What is the output of the following code?

import numpy as np
a = np.arange(10)
print(a[2:5])

a) [2, 3, 4]
b) [0, 1, 2]
c) [5, 6, 7]
d) [2, 4, 6]

Answer: a) [2, 3, 4]

Explanation: The code creates a NumPy array with elements from 0 to 9 using the arange() function. The slicing operation a[2:5] returns the elements from index 2 to index 4, which is [2, 3, 4].

4. Which of the following is used to create an identity matrix in NumPy?

a) zeros()
b) ones()
c) arange()
d) eye()

Answer: d) eye()

Explanation: The eye() function is used to create an identity matrix in NumPy.

5. What is the output of the following code?

import numpy as np
a = np.array([[1, 2], [3, 4]])
print(a)ndim)

a) 0
b) 1
c) 2
d) 3

Answer: c) 2

Explanation: The code creates a NumPy array with two dimensions and prints the number of dimensions using the ndim attribute, which is b)

6. Which of the following is used to calculate the mean of a NumPy array?

a) mean()
b) average()
c) median()
d) All of the above

Answer: d) All of the above

Explanation: The mean(), average(), and median() functions can be used to calculate the mean of a NumPy array.

7. Which of the following is used to reshape a NumPy array?

a) reshape()
b) resize()
c) Both A and B
d) None of the above

Answer: c) Both A and B

Explanation: The reshape() and resize() functions can be used to reshape a NumPy array.

8. What is the output of the following code?

import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.stack((a, b))
print(c)

a) [[1, 2, 3], [4, 5, 6]]
b) [[1, 4], [2, 5], [3, 6]]
c) [1, 2, 3, 4, 5, 6]
d) Error

Answer: b) [[1, 4], [2, 5], [3, 6]]

Explanation: The code stacks two NumPy arrays vertically using the stack() function and prints the result, which is a two-dimensional array with the elements from both arrays stacked vertically.

9. Which of the following is used to find the maximum element in a NumPy array?

a) max()
b) maximum()
c) amax()
d) All of the above

Answer: d) All of the above

Explanation: The max(), maximum(), and amax() functions can be used to find the maximum element in a NumPy array.

10. What is the output of the following code?

import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = a + b
print(c)

a) [1, 2, 3, 4, 5, 6]
b) [[1, 4], [2, 5], [3, 6]]
c) [5, 7, 9]
d) Error

Answer: c) [5, 7, 9]

Explanation: The code adds two NumPy arrays using the ‘+’ operator and prints the result, which is a new NumPy array with the elements from both arrays added together.

11. Which of the following is used to find the indices of the maximum and minimum elements in a NumPy array?

a) argmax() and argmin()
b) max() and min()
c) amax() and amin()
d) None of the above

Answer: a) argmax() and argmin()

Explanation: The argmax() and argmin() functions can be used to find the indices of the maximum and minimum elements in a NumPy array.

12. What is the output of the following code?

import numpy as np
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6], [7, 8]])
c = np.dot(a, b)
print(c)

a) [[19, 22], [43, 50]]
b) [[5, 6], [7, 8], [1, 2], [3, 4]]
c) [[1, 5], [2, 6], [3, 7], [4, 8]]
d) Error

Answer: a) [[19, 22], [43, 50]]

Explanation: The code performs matrix multiplication between two NumPy arrays using the dot() function and prints the result, which is a new NumPy array with the result of the multiplication.

13. Which of the following is used to find the standard deviation of a NumPy array?

a) std()
b) var()
c) Both A and B
d) None of the above

Answer: a) std()

Explanation: The std() function is used to find the standard deviation of a NumPy array.

14. What is the output of the following code?

import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.vstack((a, b))
print(c)

a) [[1, 2, 3], [4, 5, 6]]
b) [[1, 4], [2, 5], [3, 6]]
c) [1, 2, 3, 4, 5, 6]
d) Error

Answer: b) [[1, 4], [2, 5], [3, 6]]

Explanation: The code stacks two NumPy arrays vertically using the vstack() function and prints the result, which is a two-dimensional array with the elements from both arrays stacked vertically.

15. Which of the following is used to find the sum of the elements in a NumPy array?

a) sum()
b) cumsum()
c) All of the above
d) None of the above

Answer: a) sum()

Explanation: The sum() function is used to find the sum of the elements in a NumPy array.

16. Which of the following is used to find the median of a NumPy array?

a) median()
b) mean()
c) mode()
d) None of the above

Answer: a) median()

Explanation: The median() function is used to find the median of a NumPy array.

17. What is the output of the following code?

import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.concatenate((a, b))
print(c)

a) [[1, 2, 3], [4, 5, 6]]
b) [[1, 4], [2, 5], [3, 6]]
c) [1, 2, 3, 4, 5, 6]
d) Error

Answer: c) [1, 2, 3, 4, 5, 6]

Explanation: The code concatenates two NumPy arrays using the concatenate() function and prints the result, which is a new NumPy array with the elements from both arrays concatenated)

18. Which of the following is used to create an identity matrix in NumPy?

a) identity()
b) eye()
c) ones()
d) None of the above

Answer: b) eye()

Explanation: The eye() function is used to create an identity matrix in NumPy.

19. What is the output of the following code?

import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6]
c = np.outer(a, b)
print(c)

a) [[1, 2, 3], [4, 5, 6]]
b) [[1, 4], [2, 5], [3, 6]]
c) [1, 2, 3, 4, 5, 6]
d) Error

Answer: b) [[ 4 5 6]
[ 8 10 12]
[12 15 18]]

Explanation: The code uses the outer() function to compute the outer product of two NumPy arrays and prints the result, which is a new two-dimensional NumPy array. The outer product of two vectors a and b is a matrix where each element is the product of one element from a and one element from b)

20. Which of the following is used to compute the dot product of two NumPy arrays?

a) dot()
b) inner()
c) All of the above
d) None of the above

Answer: a) dot()

Explanation: The dot() function is used to compute the dot product of two NumPy arrays.

21. What is the output of the following code?

import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.dot(a, b)
print(c)

a) [[1, 2, 3], [4, 5, 6]]
b) [[1, 4], [2, 5], [3, 6]]
c) [1, 2, 3, 4, 5, 6]
d) 32

Answer: d) 32

Explanation: The code computes the dot product of two NumPy arrays using the dot() function and prints the result, which is a scalar value. The dot product of two vectors a and b is the sum of the products of the corresponding elements of a and b)

22. Which of the following is used to find the inverse of a matrix in NumPy?

a) inv()
b) inverse()
c) All of the above
d) None of the above

Answer: a) inv()

Explanation: The inv() function is used to find the inverse of a matrix in NumPy.

23. What is the purpose of NumPy in Python?

a) To provide a powerful N-dimensional array object
b) To provide functions for performing mathematical operations on arrays
c) To provide tools for integrating C/C++ and Fortran code with Python
d) All of the above

Answer: d) All of the above

Explanation: NumPy is a popular Python library that is widely used for numerical computing. It provides a powerful N-dimensional array object, which can be used to represent vectors, matrices, and other numerical data) NumPy also provides a variety of functions for performing mathematical operations on arrays, including mathematical functions, linear algebra functions, and random number generation functions. In addition, NumPy provides tools for integrating C/C++ and Fortran code with Python, making it a useful library for scientific computing and data analysis.

24. What does NumPy stand for?

a) Numerical Python
b) Numerical Processing
c) Numeric Parsing
d) None of the above

Answer: a) Numerical Python

Explanation: NumPy stands for Numerical Python. It is an open-source Python library that is used for scientific computing and data analysis. NumPy provides a powerful N-dimensional array object, which can be used to represent vectors, matrices, and other numerical data) It also provides a variety of functions for performing mathematical operations on arrays, including mathematical functions, linear algebra functions, and random number generation functions. NumPy is widely used in the scientific computing and data analysis communities due to its speed, efficiency, and ease of use.

25. How is the basic ndarray created in NumPy?

a) By passing a Python list or tuple to the np.array() function
b) By using the np.ndarray() constructor function
c) By converting a Python list or tuple to an ndarray using the np.asarray() function
d) By using the np.zeros() or np.ones() functions to create an array filled with zeros or ones, respectively

Answer: a) By passing a Python list or tuple to the np.array() function

Explanation: The basic ndarray in NumPy is created by passing a Python list or tuple to the np.array() function. For example, to create a one-dimensional array containing the values 1, 2, and 3, we can use the following code:

python
import numpy as np
a = np.array([1, 2, 3])

This will create an array a with three elements, which can be accessed using indexing: a[0] returns 1, a[1] returns 2, and a[2] returns c) Alternatively, we can create a two-dimensional array by passing a nested list to the np.array() function. For example:

python
b = np.array([[1, 2, 3], [4, 5, 6]])

This will create a two-dimensional array with two rows and three columns. The first row contains the values 1, 2, and 3, and the second row contains the values 4, 5, and 6. We can access elements of the array using indexing: b[0, 1] returns 2 (the element in the first row and second column), and b[1, 2] returns 6 (the element in the second row and third column).

The NumPy MCQs provide a valuable opportunity to test your knowledge and comprehension of this widely-used Python library for numerical computing. By taking the NumPy MCQ Quiz, you can improve your skills and be better equipped for real-world applications of NumPy. Remember to bookmark our Freshersnow website to stay updated with the latest technical quizzes.