1. An array data structure is a data structure consisting of a ___________(values or variables), each identified by at least one array index or key
2. The definition of an 'array' typically stands to mean a collection of data items of ____________
3. In the following example, what would be returned (in python) by print(humans[2])
4. Using the language VB.Net, if this 2d array was called 'matrix', which of the following values would locate the value of the 'x' on the grid.
5. It is helpful to visualise a 2d array as a table with a _________________________
6. 3d arrays could be visualised or imagined as a _________ with height, width and _______.
7. In Python, a multidimensional list is a __________________________
8. Analyse the image and information below. What would the output of this print call be?
9. State the output of this code snippet. Note the print call: print(matrix[1][2])
10. What is the output of this code snippet. Note the print call: print(matrix[2][2])
11. Analyse the image below which shows a 3d list. What is the output?
12. This code shows looping through a 1d list. In the output, what room is Maths allocated to?
13. In the following code ________________ have been used to calculate the output which is ___________.
a = [[1, 2, 3, 4], [5, 6], [7, 8, 9]]
s = 0
for i in range(len(a)):
for j in range(len(a[i])):
s += a[i][j]
print(s)
two nested loops / 1,2,3,4
three loops / 9
two nested loops / 45
a single for loop / 1
14. In the following excerpt, try and understand the concept and fill in the blanks.
15. Can you fill in the blanks after analysing the question?
16. The following (optional to go through) powerpoit provides a scenario for a laser tag game. Which statement is true?
17. If the user entered '4' for rows and '2' for columns, what would the output be of the following code?
row_num = int(input("Input number of rows: "))
col_num = int(input("Input number of columns: "))
multi_list = [[0 for col in range(col_num)] for row in range(row_num)]
for row in range(row_num):
for col in range(col_num):
multi_list[row][col]= row*col
print(multi_list)
[[0, 0], [0, 1], [0, 2], [0, 3]]
[[0,1], [0, 1], [0, 3], [0, 4]]
[[0, 0], [1, 1], [2, 2], [3, 3]]
[[1, 0], [2, 1], [3, 2], [0, 3]]
18. The following code 'pops' (removes) an item from the array and returns a result. What is the output?
from array import *
array_num = array('i', [1, 3, 5, 7, 9])
print("Original array: "+str(array_num))
array_num.pop(2)
print("New array: "+str(array_num))
New array: array('i', [1, 3, 7, 9])
New array: array('i', [1, 5, 7, 9])
New array: array('i', [3, 5, 7, 9])
New array: array('i', [1, 3, 5, 9])
19. Numpy is a scientific package used with Python and contains a powerful 'n' array object. Fill in the blanks for y.
import numpy as np
x = np.array([1, 2, 3, 4, 5, 6])
print("6 rows and 0 columns")
print(x.shape)
y = np.array([[1, 2, 3],[4, 5, 6],[7,8,9]])
print("(3, 3) -> _________________________ ")
print(y)
x = np.array([1,2,3,4,5,6,7,8,9])
print("Change array shape to (3, 3) -> 3 rows and 3 columns ")
x.shape = (3, 3)
print(x)
3 columns and 0 rows
3 rows and 0 columns
3 rows and 3 columns
6 rows and 3 columns
20. Because the mathematical concept of a matrix can be represented as a two-dimensional grid, two-dimensional arrays are _________________