You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30Lines changed: 30 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1530,6 +1530,36 @@ tuple()
1530
1530
1531
1531
---
1532
1532
1533
+
### Teleportation
1534
+
1535
+
Suggested in [this](https://www.reddit.com/r/Python/comments/6x6upn/wtfpython_a_collection_of_interesting_and_tricky/dme96dq/) reddit thread.
1536
+
1537
+
```py
1538
+
import numpy as np
1539
+
1540
+
def energy_send(x):
1541
+
np.array([float(x)])
1542
+
1543
+
def energy_receive():
1544
+
return np.empty((), dtype=np.float).tolist()
1545
+
```
1546
+
1547
+
**Output:**
1548
+
```py
1549
+
>>> energy_send(123.456)
1550
+
>>> energy_receive()
1551
+
123.456
1552
+
```
1553
+
1554
+
Does this deserve a Nobel prize?
1555
+
1556
+
#### 💡 Explanation:
1557
+
1558
+
* Notice that the numpy array created in the `energy_send` function isnot returned, so that memory space is free to reallocate.
1559
+
*`numpy.empty()` returns the next free memory slot without reinitializing it. This memory spot just happens to be the same one that was just freed (usually, but not always).
1560
+
1561
+
---
1562
+
1533
1563
### yielding None
1534
1564
1535
1565
Suggested by @chris-rands in [this](https://github.com/satwikkansal/wtfpython/issues/32) issue.
0 commit comments