Home »
Python
Python NumPy MCQs
NumPy is a Python package that is used to manipulate arrays of data. NumPy is an abbreviation for Numerical Python. It also includes functions for working in the areas of linear algebra, the Fourier transform, and matrices, among other things. Array objects can be created with NumPy are up to 50 times faster than regular Python lists. In NumPy, Ndarray is the name given to the array object.
Python NumPy MCQs: This section contains multiple-choice questions and answers on Python NumPy. These MCQs are written for beginners as well as advanced, practice these MCQs to enhance and test the knowledge of Python NumPy.
List of Python NumPy MCQs
1. What is the purpose of NumPy in Python?
- To do numerical calculations
- To do scientific computing
- Both A and B
- None of the mentioned above
Answer: C) Both A and B
Explanation:
NumPy is an abbreviation for 'Numerical Python.' NumPy is a Python library that allows users to perform mathematical and logical operations on arrays. As a result, NumPy is considered a Python package. There are multidimensional array objects and a collection of routines for processing the arrays in this library, which may be found here. NumPy consists of multidimensional array objects as well as a collection of procedures for manipulating and processing those arrays.
Discuss this Question
2. NumPy package is capable to do fast operations on arrays.
- True
- False
Answer: A) True
Explanation:
NumPy package is capable to do fast operations on arrays including mathematical, logical, shape manipulation, sorting, selecting, I/O, discrete Fourier transforms, basic linear algebra, basic statistical operations, random simulation and much more.
Discuss this Question
3. Amongst which Python library is similar to Pandas?
- NPy
- RPy
- NumPy
- None of the mentioned above
Answer: C) NumPy
Explanation:
Like NumPy, Pandas is one of the most extensively used python libraries in data science, and it is similar to NumPy. Data structures and analytical tools that are high-performance and simple to use are provided by the system. The Pandas library, in contrast to the NumPy library, which provides objects for multi-dimensional arrays, provides an in-memory two-dimensional table object called DataFrame.
Discuss this Question
4. Amongst which of the following is true with reference to Pip in Python?
- Pip is a standard package management system
- It is used to install and manage the software packages written in Python
- Pip can be used to search a Python package
- All of the mentioned above
Answer: D) All of the mentioned above
Explanation:
Pip is a standard package management system that is used to install and manage software packages that are written in the Python programming language.
Discuss this Question
5. NumPy arrays can be ___.
- Indexed
- Sliced
- Iterated
- All of the mentioned above
Answer: D) All of the mentioned above
Explanation:
The index value of an array starts at zero, and each element is referred by the index value of the previous member.
Slicing - Slicing is used when we need to extract a portion of an array from another. This is accomplished by the use of slicing. We can indicate which part of the array should be sliced by using the [start: end] syntax in conjunction with the array name to give the start and end index values.
Iterating - The first axis of a multidimensional array is used to iterate through the arrays, for example.
for x in b:
print(x)
Discuss this Question
6. Observe the following code and identify what will be the outcome?
import numpy as np
a=np.array([1,2,3,4,5,6])
print(a)
- [1 2 3 4 5]
- [1 2 3 4 5 6]
- [0 1 2 3 4 5 6]
- None of the mentioned above
Answer: B) [1 2 3 4 5 6]
Explanation:
In the above code, an array of six elements declared and assign it to the variable a. In the next line of code, a is printing. So, all the elements which are in array a will be print on screen.
Discuss this Question
7. Observe the following code and identify what will be the outcome?
import numpy as np
x = np.array([[0, 1],
[2, 3]])
np.transpose(x)
-
array([[0, 2],
[1, 3]])
-
array([[0, 1],
[2, 3]])
-
array([[2, 3],
[0, 1]])
- None of the mentioned above
Answer: A)
array([[0, 2],
[1, 3]])
Explanation:
In the above code, an array has been declared and stored in a variable x. And then, matrix transposed and print.
Discuss this Question
8. Observe the following code and identify what will be the outcome?
import numpy as np
a = np.array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
b = a
b is a
- True
- False
Answer: A) True
Explanation:
In the above code, the matrix has assigned to the variable a and then copy it to the variable b. Hence, when we will run the code it will print true i.e Boolean value.
Discuss this Question
9. The ix_ function can be used to combine different vectors.
- True
- False
Answer: A) True
Explanation:
To acquire the result for each n-uplet, the ix_ function can be used to mix different vectors together in one operation.
Discuss this Question
10. Observe the following code and identify what will be the outcome?
import numpy as np
a = np.array([10, 20, 30, 40])
b = np.array([18, 15, 14])
c = np.array([25, 24, 26, 28, 23])
x, y, z = np.ix_(a, b, c)
print(x)
-
[[[10]]
[[20]]
[[30]]
[[40]]]
-
[[[1]]
[[2]]
[[3]]
[[4]]
[[5]]]
-
[[[18]]
[[15]]
[[[14]]]
- None of the mentioned above
Answer: A)
[[[10]]
[[20]]
[[30]]
[[40]]]
Explanation:
To acquire the result for each n-uplet, the ix_ function can be used to mix different vectors together in one operation. In this case, if you wish to compute all of the a+b*c for all of the triplets derived from each of the vectors a, b, and c.
Discuss this Question
11. What will be the output of the following Python code?
from numpy import random
x = random.randint(100)
print(x)
- 56
- 26
- 40
- All of the mentioned above
Answer: D) All of the mentioned above
Explanation:
In the above code, random.randint(100) function has been used which is used to create any integer number till 100.
Discuss this Question
12. Binomial Distribution is a Discrete Distribution.
- True
- False
Answer: A) True
Explanation:
A Discrete Distribution is the same as a Binomial Distribution. If you toss a coin, the outcome will be either heads or tails. This term explains the outcome of binary circumstances. It is comprised of three parameters:
- n - is the number of tries.
- p - denotes the likelihood that each trial will occur (e.g. for toss of a coin 0.5 each).
- size - The size of the array that was returned.
Discuss this Question
13. Using ndim we can find -
- We can find the dimension of the array
- Size of array
- Operational activities on Matrix
- None of the mentioned above
Answer: A) We can find the dimension of the array
Explanation:
We can determine the dimension of an array, regardless of whether it is a two-dimensional array or a single-dimensional array.
Discuss this Question
14. Observe the code and identify the outcome:
from numpy import random
x = random.binomial(n=100, p=0.5, size=10)
print(x)
- [41 53 50 52 60 47 50 50 50 46]
- [50 52 60 47 50 50 50 46]
- [41 53 50 52 60 47 50]
- None of the mentioned above
Answer: A) [41 53 50 52 60 47 50 50 50 46]
Explanation:
In the above code, binomial distribution has been used so the outcome of the code will be [41 53 50 52 60 47 50 50 50 46].
Discuss this Question
15. What will be the output of following Python code?
import numpy as np
a = np.array([(10,20,30)])
print(a.itemsize)
- 10
- 9
- 8
- All of the mentioned above
Answer: C) 8
Explanation:
Using itemsize, we can determine the byte size of each element. In the above code, a single-dimensional array has built, and we can determine the size of each element with the aid of the itemsize function.
Discuss this Question