Function Differences with tf.eye
tf.eye
tf.eye(
num_rows,
num_columns=None,
batch_shape=None,
dtype=tf.dtypes.float32,
name=None
) -> Tensor
For more information, see tf.eye.
mindspore.ops.eye
mindspore.ops.eye(n, m, t) -> Tensor
For more information, see mindspore.ops.eye.
Differences
TensorFlow: It is possible to accept batch_shape
in the parameters in TensorFlow to make the output have such a shape.
MindSpore: The number of columns and data types cannot be defaulted, and there is no difference in function.
Categories |
Subcategories |
TensorFlow |
MindSpore |
Differences |
---|---|---|---|---|
Parameters |
Parameter 1 |
num_rows |
n |
Same function, different parameter names |
Parameter 2 |
num_columns |
m |
Specifies the number of columns of the tensor. Optional in TensorFlow; without this parameter, a tensor with the same number of columns and rows is returned; required in MindSpore |
|
Parameter 3 |
batch_shape |
- |
Makes the output have the specified shape. MindSpore does not have this parameter. For example, |
|
Parameter 4 |
dtype |
t |
The name is different, optional in TensorFlow. If not, the default is |
|
Parameter 5 |
name |
- |
Not involved |
Differences Analysis and Examples
Code Example 1
TensorFlow can default
num_columns
, and MindSpore cannot default.
# TensorFlow
import tensorflow as tf
e1 = tf.eye(3)
print(e1.numpy())
# [[1. 0. 0.]
# [0. 1. 0.]
# [0. 0. 1.]]
# MindSpore
import mindspore
import mindspore.ops as ops
e1 = ops.eye(3, 3, mindspore.float32)
print(e1.numpy())
# [[1. 0. 0.]
# [0. 1. 0.]
# [0. 0. 1.]]
Code Example 2
TensorFlow can default
dtype
, and MindSpore cannot default.
# TensorFlow
import tensorflow as tf
e2 = tf.eye(3, 2)
print(e2.numpy())
# [[1. 0.]
# [0. 1.]
# [0. 0.]]
# MindSpore
import mindspore
import mindspore.ops as ops
e2 = ops.eye(3, 2, mindspore.float32)
print(e2)
# [[1. 0.]
# [0. 1.]
# [0. 0.]]