Tensor contraction of a and b along specified axes.
Aliases:
tf.compat.v1.linalg.tensordot
tf.compat.v1.tensordot
tf.compat.v2.linalg.tensordot
tf.compat.v2.tensordot
tf.linalg.tensordot
tf.tensordot(
a,
b,
axes,
name=None
)
Tensordot (a
lso known a
s tensor contra
cti
on) sums the product of elements from a
a
nd b
over the i
ndi
ces speci
fi
ed b
y a
a
xes a
nd b
a
xes. The li
sts a
a
xes a
nd b
a
xes speci
fy those pa``i
rs of a
xes a
long whi
ch to contra
ct the tensors. The a
xi
s a
a
xes[i
] of a
must ha
ve the sa
me di
mensi
on a
s a
xi
s b
a
xes[i
] of b
for a
ll i
i
n ra
nge(0, len(a
a
xes)). The li
sts a
a
xes a
nd b
_a
xes must ha
ve i
denti
ca
l length a
nd consi
st of uni
que i
ntegers tha
t speci
fy va
li
d a
xes for ea
ch of the tensors.
This operation corresponds to numpy.tensordot(a, b, axes).
Exa
mple 1: When a
a
nd b
a
re ma
trices (order 2), the ca
se a
xes = 1 is equiva
lent to ma
trix multiplica
tion.
Exa
mple 2: When a
a
nd b
a
re ma
trices (order 2), the ca
se a
xes = [[1], [0]] is equiva
lent to ma
trix multiplica
tion.
Example 3: Suppose that
and
represent two tensors of order 3. Then, contract(a, b, [[0], [2]]) is the order 4 tensor
whose entry corresponding to the indices
is given by:
.
In general, order(c) = order(a) + order(b) - 2*len(axes[0]).
Args:
a
:Tensor
of typefloat32
orfloat64
.b
:Tensor
with the sa
me typea
sa
.a
xes: Eithera
sca
la
rN
, ora
list ora
nint32
Tensor
of sha
pe [2, k]. Ifa
xes isa
sca
la
r, sum over the la
stN
a
xes ofa
a
nd the firstN
a
xes ofb
in order. Ifa
xes isa
list orTensor
the firsta
nd second row conta
in the set of unique integers specifyinga
xesa
long which the contra
ction is computed, fora
a
ndb
, respectively. The numb
er ofa
xes fora
a
ndb
mustb
e equa
l.name
: Aname
for the opera
tion (optiona
l).
Returns:
A Tensor
with the sa
me type a
s a
.
Raises:
ValueError
: If the sha
pes ofa
,b
,a
nda
xesa
re incompa
tib
le.IndexError
: If the va
lues ina
xes exceed the ra
nk of the corresponding tensor.