These are chat archives for numpy/numpy

15th
Jun 2017
Szabolcs Dombi
@cprogrammer1994
Jun 15 2017 09:50
what is the fastest way to do this
(a.transpose() @ b.transpose()).transpose()
# a and b are 4x4 numpy matrices
Nathaniel J. Smith
@njsmith
Jun 15 2017 09:51
probably np.dot(b, a)
Szabolcs Dombi
@cprogrammer1994
Jun 15 2017 09:56
dot gives a different result
import numpy as np

a = np.array((
    (1, 2, 3, 4),
    (0, 1, 0, 0),
    (0, 0, 1, 0),
    (0, 0, 0, 1),
))

b = np.array((
    (2, 0, 7, 0),
    (0, 2, 0, 0),
    (0, 2, 2, 0),
    (0, 2, 0, 2),
))

print(a @ b)
print(np.dot(a, b))
print((a.transpose() @ b.transpose()).transpose())
Nathaniel J. Smith
@njsmith
Jun 15 2017 09:56
np.dot(b, a), not np.dot(a, b)
Szabolcs Dombi
@cprogrammer1994
Jun 15 2017 09:57
thank you!