Complete the code to convert the 2D array to 1D using flatten().
import numpy as np arr = np.array([[1, 2], [3, 4]]) flat_arr = arr.[1]()
The flatten() method returns a copy of the array collapsed into one dimension.
Complete the code to convert the 2D array to 1D using ravel().
import numpy as np arr = np.array([[5, 6], [7, 8]]) raveled_arr = arr.[1]()
The ravel() method returns a flattened view of the array when possible, which is more memory efficient.
Fix the error in the code to flatten the array correctly.
import numpy as np arr = np.array([[9, 10], [11, 12]]) flat_arr = arr.[1]()
Methods flatten() and ravel() require parentheses to be called. Without parentheses, they are just references to the method.
Fill both blanks to create a 1D array from 2D using flatten() and check its type.
import numpy as np arr = np.array([[13, 14], [15, 16]]) flat_arr = arr.[1]() arr_type = type([2])
Use flatten() to get a 1D copy, then check the type of the flattened array variable.
Fill all three blanks to flatten the array with ravel(), modify the first element, and print the original array.
import numpy as np arr = np.array([[17, 18], [19, 20]]) raveled_arr = arr.[1]() raveled_arr[0] = [2] print(arr[0, 0] == [3])
Using ravel() returns a view, so modifying it changes the original array. Setting first element to 100 updates arr[0,0] to 100.