0
0
NumPydata~10 mins

Why math functions matter 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 calculate the square root of each number in the array.

NumPy
import numpy as np
numbers = np.array([4, 9, 16, 25])
sqrt_values = np.[1](numbers)
print(sqrt_values)
Drag options to blanks, or click blank then click option'
Asqrt
Bsquare
Clog
Dexp
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.square instead of np.sqrt, which squares the numbers instead of finding roots.
Using np.log or np.exp which calculate logarithm or exponentials, not roots.
2fill in blank
medium

Complete the code to calculate the natural logarithm of each number in the array.

NumPy
import numpy as np
values = np.array([1, 10, 100, 1000])
log_values = np.[1](values)
print(log_values)
Drag options to blanks, or click blank then click option'
Aexp
Bsqrt
Cabs
Dlog
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.sqrt which calculates square roots, not logarithms.
Using np.exp which calculates exponentials, the opposite of logarithms.
3fill in blank
hard

Fix the error in the code to calculate the exponential of each number in the array.

NumPy
import numpy as np
values = np.array([0, 1, 2, 3])
exp_values = np.[1](values)
print(exp_values)
Drag options to blanks, or click blank then click option'
Alog
Bexp
Csqrt
Dabs
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.log which calculates logarithms, not exponentials.
Using np.sqrt which calculates square roots.
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 letters.

NumPy
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 '<=' instead of '>' which would select words of length 3 or less.
Using 'word' instead of 'len(word)' for the dictionary values.
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 letters.

NumPy
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 '>' which would select shorter words.
Using 'word' instead of 'len(word)' for values.