0
0
SciPydata~10 mins

Matrix creation and operations in SciPy - Interactive Code Practice

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

Complete the code to create a 3x3 identity matrix using NumPy.

SciPy
from numpy import eye
matrix = eye([1])
Drag options to blanks, or click blank then click option'
A5
B2
C4
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using a size other than 3 will create a matrix of wrong dimensions.
Confusing eye with ones or zeros.
2fill in blank
medium

Complete the code to create a 2x4 matrix of zeros using NumPy.

SciPy
from numpy import zeros
matrix = zeros(([1]))
Drag options to blanks, or click blank then click option'
A2, 2
B4, 2
C2, 4
D3, 4
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping rows and columns in the tuple.
Passing separate arguments instead of a tuple.
3fill in blank
hard

Fix the error in the code to multiply two matrices using NumPy.

SciPy
from numpy import array
A = array([[1, 2], [3, 4]])
B = array([[5, 6], [7, 8]])
result = A [1] B
Drag options to blanks, or click blank then click option'
A@
B*
Cdot
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using * instead of @ for matrix multiplication.
Trying to use dot as an operator instead of a method.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.

SciPy
words = ['data', 'science', 'is', 'fun']
lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 3
Cword.startswith('s')
Dword.upper()
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using a wrong condition that filters incorrectly.
5fill in blank
hard

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

SciPy
words = ['cat', 'dog', 'elephant']
result = { [1]: [2] for word in words if [3] }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Clen(word) > 2
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase instead of uppercase for keys.
Incorrect condition that filters out all words.