wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Numpy

Total questions: 66

Worksheet time: 1hrs 19mins

Name
Class
Date
1.
  1. Which of the following creates a 1D array with elements [0, 1, 2, 3, 4]?

a)

np.linspace(0, 5, 5)

b)

np.arange(0, 5)

c)

np.ones(5)

d)

np.zeros(5)

2.

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

a)

1

b)

2

c)

3

d)

4

3.
  1. How would you create a 2x3 array filled with random numbers between 0 and 1?

a)

np.random.randint(0, 1, (2, 3))

b)

np.random.rand(2, 3)

c)

np.ones((2, 3))

d)

np.zeros((2, 3))

4.

Which function generates evenly spaced numbers over a specified interval?

a)

np.arange

b)

np.linspace

c)

np.random.rand

d)

np.zeros

5.

To create an array of evenly spaced numbers between 0 and 10, we use the function
np.

(a)  

6.

  1. The function np. (a)   generates a matrix where all elements are zeros.

7.

  1. The shape of a NumPy array can be changed using the (a)   method.

8.

The function np. (a)   generates an array of random numbers drawn from a standard normal distribution.

9.

  1. To create an identity matrix of size 4x4, the function (a)   is used.

10.

In NumPy, the function np. (a)   returns the index of the maximum value in an array.

11.

  1. The function np. (a)   can be used to join arrays along different axes.

12.
  1. np.arange(0, 11, 2) will generate the array [0, 1, 2, 3, 4, 5].

a)

True

b)

False

13.
  1. NumPy arrays are mutable, meaning their values can be changed after creation.

a)

True

b)

False

14.

The method arr.reshape(3, 4) will return a reshaped version of the array, but the original array will remain unchanged unless reassigned.

a)

True

b)

False

15.

The slicing arr[:3] includes the elements from index 0 to index 3, exclusive.

a)

True

b)

False

16.

Broadcasting allows you to perform operations between arrays of different shapes without explicitly reshaping them.

a)

True

b)

False

17.
  1. The function np.ones((3, 3)) creates a 2D array of shape (3, 3) filled with zeros.

a)

True

b)

False

18.

The np.random.randint(1, 100, 10) generates 10 random integers between 1 and 100 (inclusive).

a)

True

b)

False

19.
  1. What are the two main types of arrays in NumPy?

4 lines
20.

How do you create a NumPy array from a Python list? Provide an example.

4 lines
21.

What is the difference between np.arange and np.linspace?

4 lines
22.

What does np.eye do, and how is it useful?

4 lines
23.
  1. How do you reshape an array in NumPy?

4 lines
24.
  1. What is broadcasting in NumPy, and why is it important?

4 lines
25.

How can you concatenate two arrays along rows or columns?

4 lines
26.

Describe how you can use Boolean indexing in NumPy to filter elements from an array.

4 lines
27.

What are some common mathematical operations you can perform on NumPy arrays?

4 lines
28.

  1. To create a NumPy array from a list, we use the function np. (a)   .

29.

  1. The function np. (a)   generates evenly spaced values within a specified range.

30.

  1. The np.eye(5) function creates a (a)   matrix.

31.

  1. The method (a)   is used to change the shape of an array.

32.

The function np.random. (a)   generates random numbers from a uniform distribution between 0 and 1.

33.

  1. A __________ is a 1D array, while a __________ is a 2D array in NumPy.



(a)  

34.

  1. To concatenate two arrays along rows, use the function np. (a)   .

35.

  1. The slicing notation arr[1:5] retrieves elements from index __________ to __________ (exclusive).



(a)  

36.

The function np. (a)   returns the index of the maximum value in an array.

37.
  1. np.arange(0, 10, 2) generates the array [0, 2, 4, 6, 8].

a)

True

b)

false

38.
  1. NumPy arrays are immutable and cannot be changed after creation.

a)

True

b)

False

39.

The function np.linspace(0, 5, 6) generates 6 evenly spaced numbers between 0 and 5.

a)

True

b)

False

40.

np.zeros((3, 3)) creates a 1D array with three zeros.

a)

True

b)

False

41.

Broadcasting allows NumPy arrays of different shapes to be used in arithmetic operations without explicit reshaping.

a)

True

b)

False

42.

The slicing arr[:3] includes the element at index 3.

a)

True

b)

False

43.

The function np.random.randint(1, 10, 5) generates 5 random integers between 1 and 10, inclusive.

a)

True

b)

False

44.
  1. The method reshape changes the shape of the array in-place.

a)

True

b)

False

45.
  1. An identity matrix is a square matrix with ones on the diagonal and zeros elsewhere.

a)

True

b)

False

46.

Using Boolean indexing, you can filter elements of an array based on conditions.

a)

True

b)

False

47.
  1. How does the reshape method differ from changing the shape of an array directly?

4 lines
48.

What is the difference between np.random.rand and np.random.randn?

4 lines
49.
  1. How can you ensure that a sliced array does not modify the original array in NumPy?

4 lines
50.

Describe how you would extract a subarray from a 3x3 matrix containing only the last two rows and the last two columns.

(a)  

51.

What is the output of np.arange(1, 10).reshape(3, 3)[1, 2]?

(a)  

52.

The function np.random. (a)   generates random integers within a specified range.

53.

  1. To access the element in the second row and third column of a 2D array, you can use the notation arr[__________, __________].



(a)  

54.

The np. (a)   function generates an array of evenly spaced values based on a step size.

55.

  1. The attribute arr. (a)   is used to find the shape of an array.

56.

  1. The function np. (a)   is used to join arrays along a specified axis.

57.

To replace all elements in an array slice with the value 100, you can use the syntax arr[0:5] = (a)   .

58.

The slicing syntax arr[:, 1] selects all elements from the (a)   column of a 2D array.

59.

The function np.linspace(0, 1, 5) generates 4 evenly spaced numbers between 0 and 1.

a)

True

b)

False

60.
  1. The function np.random.randint(1, 5) can return the value 5.

a)

True

b)

False

61.

You can use the axis parameter in np.concatenate to specify whether to concatenate along rows or columns.

a)

True

b)

False

62.
  1. Fancy indexing allows for selecting multiple rows or columns in any order.

a)

True

b)

False

63.

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

a)

[1, 2, 3, 4]

b)

[4, 3, 2, 1]

c)

[2, 1, 4, 3]

d)

[3, 2, 1, 4]

64.
  1. How can you create an array of 10 random integers between 50 and 100?

4 lines
65.

In NumPy, the term (a)   refers to the ability to perform operations on arrays of different shapes

66.

The function np. (a)   can be used to generate an array of logarithmically spaced numbers.