wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Play with Python Lib

Total questions: 30

Worksheet time: 5mins

Name
Class
Date
1.

What is a correct syntax to create a NumPy array?

a)

np.createArray([1, 2, 3, 4, 5])

b)

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

c)

np.object([1, 2, 3, 4, 5])

2.

What is a correct syntax to check the number of dimensions in an array?

a)

np.dim()

b)

np.dim

c)

np.ndim

d)

np.ndim()

3.

Which of the following arrays is a two dimensional (2-D) array?

a)

42

b)

[[1, 2, 3], [4, 5, 6]]

c)

[1, 2, 3, 4, 5]

4.

How we can change the shape of the Numpy array in python?

a)

By Shape()

b)

By reshape()

c)

By ord()

d)

By change()

5.

How we can find the type of numpy array in python ?

a)

arr.dtype

b)

arr.ntype

c)

arr.data_type

d)

arr.type()

6.

How we install Numpy in the system ?

a)

install numpy

b)

pip install python numpy

c)

pip install numpy

d)

pip install numpy python

7.

It is possible to convert the Numpy array to list in python ?

a)

yes

b)

no

c)

sometimes

d)

none of the above

8.

What is a correct syntax to print the first item of an array?

a)

print(myArr[1])

b)

print(myArr,1)

c)

print(myArr[0])

9.

What is a correct syntax to print the number 16 from the array below:


arr = np.array([[2,4,6,8,10], [12,14,16,18,20]])

a)

print(arr[7, 2])

b)

print(arr[3, 0])

c)

print(arr[1, 2])

10.

What is a correct syntax to print the numbers [9, 12, 15] from the array below:


arr = np.array([3,6,9,12,15,18,21])

a)

print(arr[2:4])

b)

print(arr[3:6])

c)

print(arr[2:6])

d)

print(arr[2:5])

11.

Which syntax would print the array as in reverse order:


arr = np.array([1,2,3,4,5,6,7])

a)

print(arr[3:])

b)

print(arr[0:7])

c)

print(arr[::-1])

d)

print(arr[:-1:])

12.

What is the use of the zeros() function in Numpy array in python ?

a)

To make a Matrix with all element 0

b)

To make a Matrix with all diagonal element 0

c)

To make a Matrix with first row 0

d)

None of the above

13.

Which of the following counts the number of elements in Numpy array ?

a)

count()

b)

return()

c)

shape()

d)

size()

14.

Which of the following is correct way to import the Numpy module in your program ?

a)

import numpy

b)

import numpy as np

c)

All of the above

d)

from numpy import *

15.

Only one of the following statements is true when it comes to Views in NumPy, which one?

a)

The view SHOULD NOT be affected by the changes made to the original array.

b)

The view SHOULD be affected by the changes made to the original array.

16.

Only one of the following statements is true when it comes to Copies in NumPy, which one?

a)

The copy SHOULD be affected by the changes made to the original array.

b)

The copy SHOULD NOT be affected by the changes made to the original array.

17.

In NumPy, what does the SHAPE of an array mean?

a)

The shape is the number of rows.

b)

The shape is the number of columns

c)

The shape is the number of elements in each dimension.

18.

What is a correct syntax to return the shape of an array?

a)

arr.shape

b)

shape(arr)

c)

arr.shape()

19.

What is a correct method to join two or more arrays?

a)

join()

b)

concatenate()

c)

array_join()

20.

What is a correct method to split arrays?

a)

vstack()

b)

hstack()

c)

array_split()

d)

All the other 3 answers are correct

21.

What is a correct method to search for a certain value in an array?

a)

search()

b)

where()

c)

find()

22.

What is a correct syntax to return the index of all items that has the value 4 from the array below:


arr = np.array([1,4,3,4,5,4,4])?

a)

np.where(arr == 4)

b)

arr.where()

c)

arr.search(4)

23.

What is a correct method to sort the elements of an array?

a)

orderby()

b)

order()

c)

sort()

24.

When using the NumPy random module, how can you return a random number from 0 to 100?

a)

random.randint(100)

b)

random.rand()

c)

random.rand(100)

25.

What is a correct syntax to mathematically add the numbers of arr1 to the numbers of arr2?

a)

np.append(arr1, arr2)

b)

sum(arr1, arr2)

c)

np.add(arr1, arr2)

26.

What is a correct syntax to subtract the numbers from arr1 with the numbers from arr2?

a)

np.minus(arr1, arr2)

b)

np.min(arr1, arr2)

c)

np.sub(arr1, arr2)

d)

np.substract(arr1, arr2)

27.

What would be the answer of this cummulative summation in NumPy?


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

print(np.cumsum(arr))

a)

[3 6 9]

b)

[1 3 6]

c)

[9]

d)

[6]

28.

mat1 = np.array([[1,2,3],[4,5,6], [7,8,9]])

print(np.add(mat1, 1))

a)

[[ 2, 3, 4],

[ 5, 6, 7],

[ 8, 9, 10]]

b)

[[ 2, 3, 4],

[ 4, 5, 6],

[ 7, 8, 9]]

c)

[[1, 2, 3],

[4, 5, 6],

[7, 8, 9]]

29.

mat = np.array([[14, 5, 8, 10, 3],

[ 5, 14, 5, 9, 14],

[ 7, 8, 2, 13, 4],

[ 9, 12, 3, 6, 8],

[14, 5, 12, 4, 11]])

print(mat[1:4, 2:])

a)

[[ 5, 9, 14],

[ 2, 13, 4],

[ 3, 6, 8]]

b)

[[ 8, 2, 13, 4]]

c)

[[ 5, 9, 14],

[ 2, 13, 4],

[ 3, 6, 8],

[12, 4, 11]]

30.

Which is not a python library?

a)

numpy

b)

tensorflow

c)

keras

d)

sqrt