0
0
NumPydata~10 mins

np.exp() and np.log() in NumPy - Interactive Code Practice

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

Complete the code to calculate the exponential of each element in the array.

NumPy
import numpy as np
arr = np.array([1, 2, 3])
result = np.[1](arr)
print(result)
Drag options to blanks, or click blank then click option'
Aexp
Blog
Csqrt
Dsin
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.log() instead of np.exp()
Using math.exp() which does not work element-wise on arrays
2fill in blank
medium

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

NumPy
import numpy as np
arr = np.array([1, np.e, np.e**2])
result = np.[1](arr)
print(result)
Drag options to blanks, or click blank then click option'
Aexp
Blog10
Csqrt
Dlog
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.exp() instead of np.log()
Using np.log10() which calculates log base 10
3fill in blank
hard

Fix the error in the code to correctly compute the exponential of the array elements.

NumPy
import numpy as np
arr = [1, 2, 3]
result = np.[1](arr)
print(result)
Drag options to blanks, or click blank then click option'
Aexp
Bsqrt
Carray
Dlog
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.log() which calculates logarithm
Trying to call np.array() as a function on the list
4fill in blank
hard

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

NumPy
words = ['data', 'is', 'fun', 'and', 'easy']
lengths = {word: [1] for word in words if [2]
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
Bword > 3
Clen(word) > 3
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself instead of its length
Comparing the word string directly to a number
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and their logarithm values as values, but only include words with length greater than 2.

NumPy
import numpy as np
words = ['hi', 'log', 'data', 'np']
result = { [1]: np.[2](len(word)) for word in words if len(word) [3] 2 }
print(result)
Drag options to blanks, or click blank then click option'
Aword.upper()
Blog
C>
Dexp
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.exp instead of np.log
Not converting words to uppercase
Using wrong comparison operator