python - Compute numpy.inner() over first (instead of last) axis -



python - Compute numpy.inner() over first (instead of last) axis -

i'm trying create function numpy.inner, sums on first axis of both arrays instead of lastly axis. i'm using tensordot rollaxis:

def inner1(a, b): homecoming numpy.tensordot(numpy.rollaxis(a, 0, len(a.shape)), b, 1)

but i'm wondering: there improve way? perhaps 1 doesn't require me roll axes?

i sense einsum should create possible, i'm not sure how utilize here. seems require me hard-code dimensionality of a , b when specify subscripts string, can't here because there no particular requirement on input dimensionality.

(note: am aware there performance implications summing on first axis instead of last, i'm ignoring them here.)

i think want np.tensordot(a, b, (0, 0)).

python arrays numpy linear-algebra inner-product

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -