Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save manuel-delverme/8d53afe46b222ac913b023e5155df650 to your computer and use it in GitHub Desktop.
Save manuel-delverme/8d53afe46b222ac913b023e5155df650 to your computer and use it in GitHub Desktop.
transpose vs T vs reshape
import timeit
setup = 'import numpy as np; a=np.random.randn(10)'
reshape = timeit.Timer('a.reshape(-1, 10)', setup=setup)
transp = timeit.Timer('a.transpose()', setup=setup)
T = timeit.Timer('a.T', setup=setup)
print("reshape", reshape.timeit(number=int(1e6)))
print("transp", transp.timeit(number=int(1e6)))
print("T", T.timeit(number=int(1e6)))
print("reshape", reshape.timeit(number=int(1e6)))
print("transp", transp.timeit(number=int(1e6)))
print("T", T.timeit(number=int(1e6)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment