Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.inner

numpy.inner(a,b)

Inner product of two arrays.

Ordinary inner product of vectors for 1-D arrays (without complexconjugation), in higher dimensions a sum product over the last axes.

Parameters:

a, b : array_like

Ifa andb are nonscalar, their last dimensions must match.

Returns:

out : ndarray

out.shape = a.shape[:-1] + b.shape[:-1]

Raises:

ValueError

If the last dimension ofa andb has different size.

See also

tensordot
Sum products over arbitrary axes.
dot
Generalised matrix product, using second last dimension ofb.
einsum
Einstein summation convention.

Notes

For vectors (1-D arrays) it computes the ordinary inner-product:

np.inner(a,b)=sum(a[:]*b[:])

More generally, ifndim(a) = r > 0 andndim(b) = s > 0:

np.inner(a,b)=np.tensordot(a,b,axes=(-1,-1))

or explicitly:

np.inner(a,b)[i0,...,ir-1,j0,...,js-1]=sum(a[i0,...,ir-1,:]*b[j0,...,js-1,:])

In additiona orb may be scalars, in which case:

np.inner(a,b)=a*b

Examples

Ordinary inner product for vectors:

>>>a=np.array([1,2,3])>>>b=np.array([0,1,0])>>>np.inner(a,b)2

A multidimensional example:

>>>a=np.arange(24).reshape((2,3,4))>>>b=np.arange(4)>>>np.inner(a,b)array([[ 14,  38,  62],       [ 86, 110, 134]])

An example whereb is a scalar:

>>>np.inner(np.eye(2),7)array([[ 7.,  0.],       [ 0.,  7.]])

Previous topic

numpy.vdot

Next topic

numpy.outer

  • © Copyright 2008-2009, The Scipy community.
  • Last updated on Jun 10, 2017.
  • Created usingSphinx 1.5.3.

[8]ページ先頭

©2009-2025 Movatter.jp