Relative Content

Tag Archive for pythonarraysnumpy

Multiplying a 2D array with a 3D array of vectors in Numpy

I have a dxd matrix that I would like to multiply with a dx1xn matrix. The idea is to get back another dx1xn matrix, so I would essentially like to multiply each dxd matrix with each dx1 matrix n times along that third axis. I have no idea how to go about this though. I have tried np.apply_along_axis and np.apply_over_axes, but the first only selects one axis rather than the dx1 matrices, and the second doesn’t do what I want either.

Create new matrix with sum of all n*n submatrixes sum without using loops

I have a starting array (a) and I’m using loops to create a new matrix (b) where every element represents the sum of every unique subarray n*n (0+1+5+6=12, 1+2+6+7=16, …). Can I achieve the same result without using loops by inbuilt Numpy methods? I tried np.reshape, but I can’t count intersecting subarrays with it.

Multiply array of matrices with array of vectors in Numpy

I have an array of matrices A of shape A.shape = (N, 3, 3) and an array of vectors V of shape V.shape = (N, 3). I want to get an (N, 3) array, where each vector is the result of multiplying the n-th matrix with the n-th vector. Such as: