suppose that x is a 2d numpy array which of the following creates deep copy in y in python
We can create deep copy of numpy array using numpy.copy() function.
main.py
import numpy as np
# Suppose x is the 2D numpy arrayx = np.array([[1, 2], [3, 4]])
# Creating deep copy of array xy = np.copy(x)
# Modifying the copy of array yy[0][0] = 10print("Array x:", x)
print("Array y:", y)
222 chars
14 lines
Output:
main.py
Array x: [[12]
[34]]
Array y: [[102]
[ 34]]
52 chars
5 lines
As we can see that, after modifying the copy of numpy array y, numpy array x remains unchanged.