Complete the code to convert a NumPy array to a Python list.
import numpy as np arr = np.array([1, 2, 3]) py_list = arr.[1]()
to_list() which does not exist.The tolist() method converts a NumPy array to a Python list.
Complete the code to convert a Python list to a NumPy array.
import numpy as np py_list = [4, 5, 6] arr = np.[1](py_list)
tolist() which converts arrays to lists.fromlist which is not a NumPy function.The np.array() function converts a Python list to a NumPy array.
Fix the error in the code to convert a nested Python list to a NumPy array.
import numpy as np nested_list = [[1, 2], [3, 4]] arr = np.[1](nested_list)
tolist() which converts arrays to lists.fromlist which is not a valid NumPy function.Use np.array() to convert nested lists to multidimensional NumPy arrays.
Fill both blanks to create a list of lengths of strings from a list using list comprehension.
words = ['apple', 'banana', 'cherry'] lengths = [[1] for [2] in words]
word as variable but len(word) as expression without matching names.len(word) but loop variable is w (mismatch).The list comprehension uses len(w) to get length and w as the loop variable.
Fill all three blanks to create a dictionary of word lengths for words longer than 5 characters.
words = ['apple', 'banana', 'cherry', 'date'] length_dict = { [1]: [2] for [3] in words if len([3]) > 5 }
The dictionary comprehension uses word as key, len(word) as value, and loops with word.
