0
0
Data Analysis Pythondata~10 mins

Array arithmetic (element-wise) in Data Analysis Python - Interactive Code Practice

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

Complete the code to add two arrays element-wise.

Data Analysis Python
import numpy as np

arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
result = arr1 [1] arr2
print(result)
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' causes subtraction, not addition.
Using '*' multiplies element-wise, not adds.
2fill in blank
medium

Complete the code to multiply two arrays element-wise.

Data Analysis Python
import numpy as np

arr1 = np.array([2, 4, 6])
arr2 = np.array([1, 3, 5])
result = arr1 [1] arr2
print(result)
Drag options to blanks, or click blank then click option'
A+
B//
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' adds arrays instead of multiplying.
Using '//' performs integer division, not multiplication.
3fill in blank
hard

Fix the error in the code to subtract two arrays element-wise.

Data Analysis Python
import numpy as np

arr1 = np.array([10, 20, 30])
arr2 = np.array([1, 2, 3])
result = arr1 [1] arr2
print(result)
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' adds arrays instead of subtracting.
Using '*' multiplies arrays instead of subtracting.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 3 characters.

Data Analysis Python
words = ['apple', 'bat', 'carrot', 'dog']
lengths = {word: [1] for word in words if len(word) [2] 3}
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' filters words shorter than 3 characters.
Using 'word' instead of 'len(word)' gives the word itself, not its length.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, only for words longer than 3 characters.

Data Analysis Python
words = ['apple', 'bat', 'carrot', 'dog']
result = { [1]: [2] for word in words if len(word) [3] 3 }
print(result)
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'word' instead of 'word.upper()' for keys.
Using '<' instead of '>' for filtering.