cross products with einsums
问题 I'm trying to compute the cross-products of many 3x1 vector pairs as fast as possible. This n = 10000 a = np.random.rand(n, 3) b = np.random.rand(n, 3) numpy.cross(a, b) gives the correct answer, but motivated by this answer to a similar question, I thought that einsum would get me somewhere. I found that both eijk = np.zeros((3, 3, 3)) eijk[0, 1, 2] = eijk[1, 2, 0] = eijk[2, 0, 1] = 1 eijk[0, 2, 1] = eijk[2, 1, 0] = eijk[1, 0, 2] = -1 np.einsum('ijk,aj,ak->ai', eijk, a, b) np.einsum('iak,ak-