Search Header Logo

Numpy and Pandas Quiz

Authored by Singaravelan Giridharan

Other

University

Used 3+ times

Numpy and Pandas Quiz
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What does the following NumPy code output? import numpy as np arr = np.array([1, 2, 3, 4]) print(arr.shape)

(4,)
(1, 4)
(4, 1)
4

Answer explanation

A 1D NumPy array has a shape of (n,) where n is the number of elements.

2.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What is the output of this NumPy operation? import numpy as np arr = np.array([10, 20, 30]) print(arr * 2)

[10, 20, 30, 10, 20, 30]
[20, 40, 60]
[102, 202, 302]
Error

Answer explanation

NumPy broadcasts 2 across the entire array and multiplies each element.

3.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What will the following code output? import numpy as np arr = np.array([[1, 2], [3, 4]]) print(arr.T)

[[1, 3], [2, 4]]
[[1, 2], [3, 4]]
[[1, 2, 3, 4]]
Error

Answer explanation

arr.T transposes the matrix, swapping rows and columns.

4.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What does np.zeros((2,3)) create?

A 2D array filled with random values
A 2D array of shape (2,3) filled with 0s
A 1D array of length 6 filled with 0s
An error because NumPy does not support zero arrays

Answer explanation

np.zeros((2,3)) creates a 2-row, 3-column matrix filled with zeros.

5.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

import numpy as np

arr = np.array(['A', 'B', 'C', 'D'])

print(arr.dtype)

What will be the output of the following code?

int32

float64

U1

Error

Answer explanation

np.arange(start, stop, step) generates numbers starting from 3 up to 10 (exclusive), incrementing by 2.

6.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What does the following pandas code output? import pandas as pd data = {'A': [1, 2, 3], 'B': [4, 5, 6]} df = pd.DataFrame(data) print(df.shape)

(3, 2)
(2, 3)
(3, 3)
(6,)

Answer explanation

The DataFrame has 3 rows and 2 columns, so df.shape returns (3, 2).

7.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What will df.head(2) return? import pandas as pd df = pd.DataFrame({'A': [10, 20, 30], 'B': [40, 50, 60]}) print(df.head(2))

The first 2 rows of the DataFrame
The last 2 rows of the DataFrame
The entire DataFrame
An error

Answer explanation

df.head(n) returns the first n rows of the DataFrame.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?