Skip to content

Instantly share code, notes, and snippets.

@binary10
Last active May 24, 2016 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binary10/92e787111e09a8dfd8d91be4062ffd6a to your computer and use it in GitHub Desktop.
Save binary10/92e787111e09a8dfd8d91be4062ffd6a to your computer and use it in GitHub Desktop.
Numpy ufunc.at()
"""
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