Last active
May 24, 2016 18:55
-
-
Save binary10/92e787111e09a8dfd8d91be4062ffd6a to your computer and use it in GitHub Desktop.
Numpy ufunc.at()
This file contains hidden or 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
""" | |
Initiating a 9000x9000 triangular matrix and applying XOR across all elements | |
""" | |
""" Using ufunc without at() """ | |
%%timeit | |
a = np.tri(9000,dtype=int) | |
a = np.bitwise_xor(a,1) | |
# 1 loops, best of 3: 373 ms per loop | |
""" Using simple incrementing assignment faster than ufunc """ | |
%%timeit | |
c = np.tri(9000, dtype=int) | |
c ^= 1 | |
# 1 loops, best of 3: 270 ms per loop | |
""" at() is tremendously slower than either methods above """ | |
%%timeit | |
a = np.tri(9000,dtype=int) | |
np.bitwise_xor.at(a,None,1) | |
# 1 loops, best of 3: 8.13 s per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment