tensordot

Python: numpy.dot / numpy.tensordot for multidimensional arrays

蓝咒 提交于 2021-02-10 15:14:00
问题 I'm optimising my implementation of the back-propagation algorithm to train a neural network. One of the aspects I'm working on is performing the matrix operations on the set of datapoints (input/output vector) as a batch process optimised by the numpy library instead of looping through every datapoint. In my original algorithm I did the following: for datapoint in datapoints: A = ... (created out of datapoint info) B = ... (created out of datapoint info) C = np.dot(A,B.transpose()) _________

Fastest Way to Find the Dot Product of a Large Matrix of Vectors

别说谁变了你拦得住时间么 提交于 2020-06-29 03:44:27
问题 I am looking for suggestions on the most efficient way to solve the following problem: I have two arrays called A and B. They are both of shape NxNx3. They represent two 2D matrix of positions, where each position is a vector of x, y, and z coordinates. I want to create a new array, called C, of shape NxN, where C[i, j] is the dot product of the vectors A[i, j] and B[i, j]. Here are the solutions I've come up with so far. The first uses the numpy's einsum function (which is beautifully