The duplicate will answer what, but will not adequately answer why or why it is not mentioned in the docs even though it is required. Read on for more...
There are two ways of making a deep copy of a numpy array. One way is using copy.deepcopy from the copy module. The other way is to call array.__deepcopy__ directly.
From the docs:
ndarray.__deepcopy__() → Deep copy of array.Used if
copy.deepcopyis called on an array.
The docs hint that the right way to call this function is without any argument. However....
In [47]: x
Out[47]:
array([[1, 1],
[2, 2]])
In [48]: x.__deepcopy__()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-48-00c3b8eda618> in <module>()
----> 1 x.__deepcopy__()
TypeError: __deepcopy__() takes exactly 1 argument (0 given)
A TypeError is returned! But...
In [51]: x.__deepcopy__(None)
Out[51]:
array([[1, 1],
[2, 2]])
And even...
In [52]: x.__deepcopy__([12345, 'blah blah'])
Out[52]:
array([[1, 1],
[2, 2]])
It appears this function requires an argument but that argument supposedly has no bearing on the returned copy.
This argument is not mentioned in the documentation. Is it a doc bug? Why is it even passed in if it is ignored?