Complete the code to convert the NumPy array to float type using astype().
import numpy as np arr = np.array([1, 2, 3]) arr_float = arr.[1](float) print(arr_float)
The astype() method is used to cast a NumPy array to a different type.
Complete the code to convert the integer array to string type using astype().
import numpy as np arr = np.array([10, 20, 30]) arr_str = arr.[1](str) print(arr_str)
Use astype(str) to convert the array elements to strings.
Fix the error in the code to convert the float array to integer type using astype().
import numpy as np arr = np.array([1.5, 2.7, 3.1]) arr_int = arr.[1](int) print(arr_int)
The correct method name is astype. Misspelling it causes an error.
Fill both blanks to create a dictionary with words as keys and their lengths as values, only for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = { [1] : len([2]) for [1] in words if len([1]) > 3 } print(lengths)
Use the same variable word as the key and inside len() to get the length of each word.
Fill all three blanks to create a dictionary with uppercase words as keys and their float lengths as values, only for words longer than 3 characters.
import numpy as np words = ['apple', 'bat', 'carrot', 'dog'] lengths = { [1] : np.array([len([2])]).[3](float)[0] for [2] in words if len([2]) > 3 } print(lengths)
The key is the uppercase word using word.upper(), the loop variable is word, and the length is converted to float using astype(float).