0
0
NumPydata~10 mins

Float types (float16, float32, float64) 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 create a NumPy array with float32 type.

NumPy
import numpy as np
arr = np.array([1.5, 2.5, 3.5], dtype=[1])
print(arr.dtype)
Drag options to blanks, or click blank then click option'
Afloat16
Bint32
Cfloat64
Dfloat32
Attempts:
3 left
💡 Hint
Common Mistakes
Using int32 instead of a float type.
Using float64 when float32 is asked.
2fill in blank
medium

Complete the code to convert an existing array to float64 type.

NumPy
import numpy as np
arr = np.array([1, 2, 3])
arr_float = arr.astype([1])
print(arr_float.dtype)
Drag options to blanks, or click blank then click option'
Afloat64
Bint64
Cfloat32
Dint16
Attempts:
3 left
💡 Hint
Common Mistakes
Using integer types instead of float types.
Confusing float32 with float64.
3fill in blank
hard

Fix the error in the code to create a float16 NumPy array.

NumPy
import numpy as np
arr = np.array([1.1, 2.2, 3.3], dtype=[1])
print(arr.dtype)
Drag options to blanks, or click blank then click option'
Afloat64
Bfloat32
Cfloat16
Dint16
Attempts:
3 left
💡 Hint
Common Mistakes
Using float32 or float64 instead of float16.
Using integer types by mistake.
4fill in blank
hard

Fill both blanks to create a dictionary with word lengths only for words longer than 3 characters.

NumPy
words = ['cat', 'house', 'dog', 'elephant']
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 the word itself instead of its length.
Using '<' instead of '>' in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values greater than 0.

NumPy
data = {'a': 1, 'b': -2, 'c': 3}
result = { [1]: [2] for k, v in data.items() if v [3] 0 }
print(result)
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using original keys instead of uppercase keys.
Using '<' or other operators instead of '>'.
Using keys as values or vice versa.