Quiz about Advanced NumPy

Advanced NumPy

Last Updated :
Discuss
Comments

Question 1

What does the np.broadcast_to() function do?

  • A

    Replicates a scalar value into an array

  • B

    Broadcasts an array to a new shape without copying data

  • C

    Concatenates two arrays along an axis

  • D

    Transposes an array

Question 2

Which function is used to calculate the QR decomposition of a matrix in NumPy?

  • A

    np.linalg.svd()

  • B

    np.linalg.qr()

  • C

    np.linalg.eig()

  • D

    np.linalg.solve()

Question 3

What will be the output of this code?

Python
import numpy as np
arr = np.array([[1, 2], [3, 4]])
result = np.kron(arr, np.eye(2))
print(result)


  • A

    [[1. 0. 2. 0.]

    [0. 1. 0. 2.]

    [3. 0. 4. 0.]

    [0. 3. 0. 4.]]

  • B

    [[1. 2.]

    [3. 4.]]

  • C

    [[1. 0.]

    [0. 2.]

    [3. 0.]

    [0. 4.]]

  • D

    [[1. 0. 2. 0.]

    [0. 1. 0. 2.]

    [3. 0. 4. 0.]

    [0. 3. 0. 4.]]

Question 4

Which function computes the eigenvalues and eigenvectors of a matrix?

  • A

    np.linalg.det()

  • B

    np.linalg.inv()

  • C

    np.linalg.eig()

  • D

    np.linalg.qr()

Question 5

What does the np.pad() function do in NumPy?

  • A

    Creates a zero-padded array

  • B

    Adds padding to an array along specified dimensions

  • C

    Aligns two arrays for concatenation

  • D

    Splits an array into blocks

Question 6

What will be the output of this code?

Python
import numpy as np
arr = np.array([[1, 2], [3, 4]])
result = np.linalg.svd(arr)
print([x.shape for x in result])


  • A

    [(2, 2), (2,), (2, 2)]

  • B

    [(2, 2), (1,), (2, 2)]

  • C

    [(2, 2), (2,), (2, 1)]

  • D

    Error

Question 7

What does the np.ma.masked_array() function do?

  • A

    Masks an array based on a condition

  • B

    Combines two arrays

  • C

    Creates a Boolean mask of an array

  • D

    Reshapes an array

Question 8

Which of the following is not a valid use of np.random.Generator?

  • A

    Generating random numbers with a specified seed

  • B

    Generating samples from a normal distribution

  • C

    Generating pseudorandom numbers for cryptography

  • D

    Generating random integers

Question 9

What does the np.unique() function return when return_counts=True is specified?

  • A

    Unique elements only

  • B

    A tuple of unique elements and their counts

  • C

    The first occurrence of each unique element

  • D

    An Error

Question 10

Which function in NumPy is used to calculate the Frobenius norm of a matrix?

  • A

    np.linalg.norm()

  • B

    np.linalg.det()

  • C

    np.linalg.inv()

  • D

    np.linalg.qr()

Tags:

There are 10 questions to complete.

Take a part in the ongoing discussion