Skip to content

Commit 9f4f0ad

Browse files
committed
Minor updates to documentation of pyttb.tensor.copy. Mainly making it very clear that it's a deep copy.
1 parent 9b0f88d commit 9f4f0ad

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

pyttb/tensor.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,21 @@ def copy(self) -> tensor:
227227
228228
Returns
229229
-------
230-
Copy of original tensor.
230+
Deep copy of original tensor.
231231
232232
Examples
233233
--------
234-
>>> T1 = ttb.tensor(np.ones((3, 2)))
235-
>>> T2 = T1
236-
>>> T3 = T2.copy()
237-
>>> T1[0, 0] = 3
238-
>>> T1[0, 0] == T2[0, 0]
239-
True
240-
>>> T1[0, 0] == T3[0, 0]
241-
False
234+
Observing the difference between a shallow copy and a deep copy. When the
235+
original tensor changes, so does the shallow copy, but the deep copy does not::
236+
237+
>>> T = ttb.tensor(np.ones((3, 2)))
238+
>>> T_shallow = T
239+
>>> T_deep = T.copy()
240+
>>> T[0, 0] = 3
241+
>>> T[0, 0] == T_shallow[0, 0]
242+
True
243+
>>> T[0, 0] == T_deep[0, 0]
244+
False
242245
"""
243246
return ttb.tensor(self.data, self.shape, copy=True)
244247

0 commit comments

Comments
 (0)