Function Differences with tf.keras.backend.dot

View Source On Gitee

tf.keras.backend.dot

tf.keras.backend.dot(x, y) -> Tensor

For more information, see tf.keras.backend.dot.

mindspore.ops.dot

mindspore.ops.dot(x1, x2) -> Tensor

For more information, see mindspore.ops.dot.

Differences

TensorFlow: Compute the dot product between two Tensor or Variable.

MindSpore: When both input parameters are tensor, MindSpore API implements the same function as TensorFlow, and only the parameter names are different. Supported only by TensorFlow when either of the two input parameters is a variable.

Categories

Subcategories

TensorFlow

MindSpore

Differences

Parameters

Parameter 1

x

x1

Same function, different parameter names, and MindSpore parameters can only be Tensor type

Parameter 2

y

x2

Same function, different parameter names, and MindSpore parameters can only be Tensor type

Code Example

When both input parameters are of Tensor type, the function is the same and the usage is the same.

import tensorflow as tf

x = tf.ones([2, 3])
y = tf.ones([1, 3, 2])
xy = tf.keras.backend.dot(x, y)
print(xy.numpy())
# [[[3. 3.]]
#  [[3. 3.]]]

# MindSpore
import mindspore
from mindspore import Tensor
import numpy as np

x1 = Tensor(np.ones(shape=[2, 3]), mindspore.float32)
x2 = Tensor(np.ones(shape=[1, 3, 2]), mindspore.float32)
out = mindspore.ops.dot(x1, x2)
print(out)
# [[[3. 3.]]
#  [[3. 3.]]]