def tensordot(self, other, axes):
"""Compute tensor dot product along named axes.
An error will be raised if the remaining axes of self and
other contain duplicate names.
:param other: Another named_ndarray instance
:param axes: List of axis name pairs (self_name, other_name)
to be contracted
:returns: Result as named_ndarray
"""
axes_self = [names[0] for names in axes]
axes_other = [names[1] for names in axes]
axespos_self = [self.axispos(name) for name in axes_self]
axespos_other = [other.axispos(name) for name in axes_other]
new_names = [name for name in self._axisnames if name not in axes_self]
new_names += (name for name in other._axisnames if name not in axes_other)
array = np.tensordot(self._array, other._array,
(axespos_self, axespos_other))
return named_ndarray(array, new_names)
评论列表
文章目录