0
0
NumPydata~10 mins

np.sqrt() for square roots 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 square root of 16 using numpy.

NumPy
import numpy as np
result = np.[1](16)
print(result)
Drag options to blanks, or click blank then click option'
Apower
Bsquare
Croot
Dsqrt
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.square() which squares the number instead of finding the root.
Using np.power() without the correct exponent.
2fill in blank
medium

Complete the code to calculate the square root of each element in the numpy array.

NumPy
import numpy as np
arr = np.array([4, 9, 25])
roots = np.[1](arr)
print(roots)
Drag options to blanks, or click blank then click option'
Asqrt
Broot
Csquare
Dpower
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to use np.square() which squares elements instead.
Using a non-existent function like np.root().
3fill in blank
hard

Fix the error in the code to correctly compute the square root of 49.

NumPy
import numpy as np
value = 49
result = np.[1](value)
print(result)
Drag options to blanks, or click blank then click option'
Asquare
Bsqrt
Croot
Dpow
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.square() which squares the number instead of finding the root.
Using np.pow() without the correct exponent.
4fill in blank
hard

Fill both blanks to create a dictionary with numbers as keys and their square roots as values.

NumPy
import numpy as np
numbers = [1, 4, 9, 16]
sqrt_dict = { [1]: np.[2](num) for num in numbers }
print(sqrt_dict)
Drag options to blanks, or click blank then click option'
Anum
Bsqrt
Cnumber
Dsquare
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong variable name for the key.
Using np.square() instead of np.sqrt().
5fill in blank
hard

Fill all three blanks to create a list of square roots for numbers greater than 10.

NumPy
import numpy as np
nums = [4, 16, 25, 9, 36]
sqrt_list = [np.[1](n) for n in nums if n [2] [3]]
print(sqrt_list)
Drag options to blanks, or click blank then click option'
Asquare
B>
C10
Dsqrt
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.square() instead of np.sqrt().
Using wrong comparison operators like '<' or '==' instead of '>'.
Using a wrong number for filtering.