0
0
NumPydata~10 mins

Why linear algebra matters in NumPy - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a 2x2 matrix using numpy.

NumPy
import numpy as np
matrix = np.array([1])
print(matrix)
Drag options to blanks, or click blank then click option'
A[1, 2, 3, 4]
B[[1, 2], 3, 4]
C[[1, 2, 3], [4, 5, 6]]
D[[1, 2], [3, 4]]
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a flat list instead of a list of lists.
Using uneven inner lists causing shape errors.
2fill in blank
medium

Complete the code to calculate the dot product of two vectors using numpy.

NumPy
import numpy as np
v1 = np.array([1, 2, 3])
v2 = np.array([4, 5, 6])
dot_product = np.[1](v1, v2)
print(dot_product)
Drag options to blanks, or click blank then click option'
Adot
Badd
Ccross
Dmultiply
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiply which returns element-wise product.
Using cross which calculates cross product, not dot product.
3fill in blank
hard

Fix the error in the code to compute the inverse of a matrix using numpy.

NumPy
import numpy as np
matrix = np.array([[1, 2], [3, 4]])
inverse = np.linalg.[1](matrix)
print(inverse)
Drag options to blanks, or click blank then click option'
Ainversed
Binverse
Cinv
Dinvert
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect function names like 'inverse' or 'invert'.
Trying to use non-existent functions causing AttributeError.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if the length is greater than 3.

NumPy
words = ['data', 'science', 'is', 'fun']
lengths = { [1] : len([2]) for [1] in words if len([1]) > 3 }
print(lengths)
Drag options to blanks, or click blank then click option'
Aword
Bwords
Cw
Dlen
Attempts:
3 left
💡 Hint
Common Mistakes
Using the list name instead of the loop variable inside len().
Using different variable names inconsistently.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is greater than 2.

NumPy
words = ['AI', 'ML', 'Data', 'Code']
result = { [1] : [2] for [3] in words if len([3]) > 2 }
print(result)
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Cword
Dwords
Attempts:
3 left
💡 Hint
Common Mistakes
Using the list name instead of the loop variable.
Not applying upper() to the key.
Using inconsistent variable names.