Created
December 22, 2021 11:08
-
-
Save axil/af6c4adb8c5634ff39ed9f3da1efaa90 to your computer and use it in GitHub Desktop.
positive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from time import perf_counter as clock | |
z = np.random.rand(10**7) - 0.5 | |
res = [] | |
for i in range(30): | |
r = [] | |
a = z.copy() | |
t1 = clock() | |
a = np.where(a<0, 0, a) | |
r.append(clock()-t1) | |
a = z.copy() | |
t1 = clock() | |
a[a<0] = 0 | |
r.append(clock()-t1) | |
a = z.copy() | |
t1 = clock() | |
np.putmask(a, a<0, 0) | |
r.append(clock()-t1) | |
a = z.copy() | |
t1 = clock() | |
a = np.maximum(a, 0) | |
r.append(clock()-t1) | |
a = z.copy() | |
t1 = clock() | |
a = a.clip(0) | |
r.append(clock()-t1) | |
res.append(r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment