File tree 1 file changed +12
-9
lines changed
1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -227,18 +227,21 @@ def copy(self) -> tensor:
227
227
228
228
Returns
229
229
-------
230
- Copy of original tensor.
230
+ Deep copy of original tensor.
231
231
232
232
Examples
233
233
--------
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
242
245
"""
243
246
return ttb .tensor (self .data , self .shape , copy = True )
244
247
You can’t perform that action at this time.
0 commit comments