Skip to content

Instantly share code, notes, and snippets.

@mchouza
Last active November 8, 2017 13:09
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 mchouza/2f74e3343c1848f6f6c6e7ff43563e98 to your computer and use it in GitHub Desktop.
Save mchouza/2f74e3343c1848f6f6c6e7ff43563e98 to your computer and use it in GitHub Desktop.
Type promotion
In [1]: import numpy as np
In [2]: A = np.random.normal(size=(5000, 5000))
In [3]: x = np.random.normal(size=5000) + 1j * np.random.normal(size=5000)
In [4]: %timeit np.dot(A, x)
1 loop, best of 3: 280 ms per loop
In [5]: %timeit np.dot(A, x.real) + 1j * np.dot(A, x.imag)
10 loops, best of 3: 22.1 ms per loop
In [6]: np.allclose(np.dot(A, x), np.dot(A, x.real) + 1j * np.dot(A, x.imag))
Out[6]: True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment