ADVERTISEMENT
ADVERTISEMENT

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?

  1. To do numerical calculations
  2. To do scientific computing
  3. Both A and B
  4. 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.

  1. True
  2. 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?

  1. NPy
  2. RPy
  3. NumPy
  4. 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?

  1. Pip is a standard package management system
  2. It is used to install and manage the software packages written in Python
  3. Pip can be used to search a Python package
  4. 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 ___.

  1. Indexed
  2. Sliced
  3. Iterated
  4. 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. [1 2 3 4 5]
  2. [1 2 3 4 5 6]
  3. [0 1 2 3 4 5 6]
  4. 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)
  1. array([[0, 2],
           [1, 3]])
  2. array([[0, 1],
           [2, 3]])
  3. array([[2, 3],
           [0, 1]])
  4. 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
  1. True
  2. 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.

  1. True
  2. 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)
  1. [[[10]]
    
     [[20]]
    
     [[30]]
    
     [[40]]]
  2. [[[1]]
    
     [[2]]
    
     [[3]]
    
     [[4]]
    
     [[5]]] 
  3. [[[18]]
    
     [[15]]
    
     [[[14]]]
  4. 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)
  1. 56
  2. 26
  3. 40
  4. 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.

  1. True
  2. 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 -

  1. We can find the dimension of the array
  2. Size of array
  3. Operational activities on Matrix
  4. 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)
  1. [41 53 50 52 60 47 50 50 50 46]
  2. [50 52 60 47 50 50 50 46]
  3. [41 53 50 52 60 47 50]
  4. 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)
  1. 10
  2. 9
  3. 8
  4. 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



 
 
ADVERTISEMENT


ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.