wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

NumPy Basics Quiz

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

What does NumPy stand for?

a)

Numerical Python

b)

Numbers in Python

c)

Numeric Python

d)

NumberPy

2.

Which of the following is the correct way to import NumPy?

a)

import numpy as npy

b)

import numpy as np

c)

import numpy

d)

import num as np

3.

How do you create a NumPy array?

a)

np.array([1, 2, 3])

b)

np.array{[1, 2, 3]}

c)

np.array((1, 2, 3))

d)

np.array[1, 2, 3]

4.

Which function is used to create an array filled with zeros?

a)

np.empty()

b)

np.zeros()

c)

np.zeros_like()

d)

np.fill()

5.

What function is used to create an identity matrix in NumPy?

a)

np.eye()

b)

np.identity()

c)

np.ones()

d)

np.ident()

6.

Which method is used to find the shape of a NumPy array?

a)

np.shape()

b)

array.shape

c)

array.size

d)

array.dim()

7.

What does the ndim attribute of a NumPy array return?

a)

The number of elements in the array

b)

The number of dimensions of the array

c)

The shape of the array

d)

The data type of the array elements

8.

What will the output of np.arange(3, 10, 2) be?

a)

[3, 4, 5, 6, 7, 8, 9]

b)

[3, 5, 7, 9]

c)

[3, 5, 7, 8, 9]

d)

[3, 4, 5, 6]

9.

What does np.linspace(0, 5, 10) do?

a)

Creates an array from 0 to 5 with 10 elements, equally spaced

b)

Creates an array of 10 elements from 0 to 5, excluding 5

c)

Creates an array from 0 to 10

d)

Creates a list from 0 to 5

10.

Which of the following reshapes an array of shape (4,) to (2, 2)?

a)

array.reshape(4)

b)

array.reshape(2, 2)

c)

array.shape(2, 2)

d)

np.reshape(array, (4, 1))

11.

How do you create a 1D array of ones with length 4?

a)

np.ones([4, 1])

b)

np.ones((4,))

c)

np.ones((1, 4))

d)

np.ones(4)

12.

What is the output of np.array([1, 2, 3]) * 2?

a)

[1, 2, 3, 1, 2, 3]

b)

[1, 4, 6]

c)

[2, 4, 6]

d)

Error

13.

What does the dtype attribute of a NumPy array specify?

a)

Number of elements in the array

b)

Type of the elements in the array

c)

Dimensions of the array

d)

Shape of the array

14.

Which of the following can be used to get the sum of elements in a NumPy array?

a)

np.add()

b)

np.sum()

c)

np.cumsum()

d)

np.aggregate()

15.

How would you calculate the mean of all elements in a NumPy array?

a)

np.mean(array)

b)

np.average(array)

c)

np.sum(array)

d)

array.mean()

16.

Which function is used to stack arrays vertically in NumPy?

a)

np.vstack()

b)

np.hstack()

c)

np.stack()

d)

np.concatenate()

17.

How can you transpose a NumPy array?

a)

np.transpose(array)

b)

np.flip(array)

c)

array.transpose()

d)

array.T

18.

What does np.random.rand(2, 3) generate?

a)

A 2x3 array with random floats between 0 and 1

b)

A 2x3 array with random integers between 0 and 10

c)

A 3x2 array with random floats

d)

A list of random floats

19.

What is the shape of np.ones((3, 4)).T?

a)

(4, 3)

b)

(3, 4)

c)

(4,)

d)

(12,)

20.

What function will return the maximum value in an array?

a)

np.maximum()

b)

np.max()

c)

np.argmax()

d)

np.highest()

21.

How do you flatten a multidimensional array in NumPy?

a)

array.flatten()

b)

array.reshape(-1)

c)

np.flatten(array)

d)

Both a and b

22.

Which of these will broadcast a NumPy array of shape (3, 1) with another of shape (1, 3)?

a)

(3, 3)

b)

(3,)

c)

(1,)

d)

(1, 1)

23.

What is the default data type of NumPy arrays?

a)

int

b)

float

c)

double

d)

complex

24.

How do you convert a list to a NumPy array?

a)

np.convert()

b)

np.array()

c)

np.fromlist()

d)

np.list()

25.

What is the function np.dot() used for?

a)

Matrix addition

b)

Matrix multiplication

c)

Element-wise multiplication

d)

Matrix transpose

26.

What will np.log(np.e) return?

a)

0

b)

1

c)

e

d)

Error

27.

How would you check if any element in an array is True?

a)

np.all()

b)

np.any()

c)

np.bool()

d)

np.check()

28.

Which of the following is used to return a copy of an array?

a)

array.view()

b)

array.copy()

c)

np.array_copy()

d)

array.clone()

29.

What does the function np.sqrt() compute?

a)

Square root of elements in the array

b)

Square of elements in the array

c)

Inverse of the elements

d)

Natural logarithm of the elements

30.

What does np.append() do?

a)

Inserts elements at a given index

b)

Appends an element to the end of an array

c)

Concatenates two arrays

d)

Returns a sorted array