Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a copy of the NumPy array 'a'.
NumPy
import numpy as np a = np.array([1, 2, 3]) b = a.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'view()' instead of 'copy()' which does not create a full copy.
Using 'reshape()' or 'flatten()' which change shape but not copy behavior.
✗ Incorrect
Using copy() creates a new array independent of the original.
2fill in blank
mediumComplete the code to create a view of the NumPy array 'a'.
NumPy
import numpy as np a = np.array([4, 5, 6]) b = a.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'copy()' which creates a full independent copy.
Using 'flatten()' or 'transpose()' which change shape or axes.
✗ Incorrect
Using view() creates a new array object that looks at the same data.
3fill in blank
hardFix the error in the code to create a copy of the array slice.
NumPy
import numpy as np a = np.array([7, 8, 9, 10]) slice_a = a[1:3] slice_copy = slice_a.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'view()' which still references original data.
Using 'reshape()' or 'flatten()' which do not copy data.
✗ Incorrect
To avoid referencing the original data, use copy() on the slice.
4fill in blank
hardFill both blanks to create a view and then modify it without affecting the original array.
NumPy
import numpy as np a = np.array([10, 20, 30, 40]) view_a = a.[1]() copy_a = view_a.[2]() copy_a[0] = 99
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'copy()' for the first blank which creates a copy, not a view.
Using 'view()' for the second blank which does not create an independent copy.
✗ Incorrect
First create a view with view(), then a copy with copy() to modify safely.
5fill in blank
hardFill all three blanks to create a copy of a reshaped array slice.
NumPy
import numpy as np a = np.arange(12) slice_a = a[2:10] reshaped = slice_a.[1]((2, 4)) copy_reshaped = reshaped.[2]() copy_reshaped[0, 0] = [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'view' instead of 'copy' which modifies original data.
Not reshaping before copying.
Assigning a value that is not an integer.
✗ Incorrect
First reshape the slice, then copy it, then modify the copy safely.