Complete the code to create a NumPy array from a Python list.
import numpy as np my_list = [1, 2, 3, 4] arr = np.[1](my_list) print(arr)
The np.array() function converts a Python list into a NumPy array, enabling efficient numerical operations.
Complete the code to convert a NumPy array back to a Python list.
import numpy as np arr = np.array([5, 6, 7]) py_list = arr.[1]() print(py_list)
The tolist() method converts a NumPy array into a Python list. The parentheses are required to call the method.
Fix the error in the code to create a NumPy array from a list of lists.
import numpy as np list_of_lists = [[1, 2], [3, 4]] arr = np.[1](list_of_lists) print(arr.shape)
The np.array() function correctly creates a 2D NumPy array from a list of lists. fromlist is not a valid NumPy function.
Fill both blanks to create a NumPy array and then convert it to a Python list.
import numpy as np py_list = [[10, 20], [30, 40]] arr = np.[1](py_list) converted_list = arr.[2]() print(converted_list)
First, np.array() creates a NumPy array from the Python list. Then, tolist() converts the array back to a Python list.
Fill all three blanks to create a NumPy array, convert it to a list, and then create a new array from that list.
import numpy as np original_list = [1, 2, 3] arr1 = np.[1](original_list) list_from_arr = arr1.[2]() arr2 = np.[3](list_from_arr) print(arr2)
np.asarray() creates an array from the list. Then tolist() converts it back to a Python list. Finally, np.array() creates a new array from that list.