代码拉取完成,页面将自动刷新
tf.expand_dims(x, axis, name=None) -> Tensor
For more information, see tf.expand_dims.
mindspore.ops.expand_dims(input_x, axis) -> Tensor
For more information, see mindspore.ops.expand_dims.
TensorFlow: Add an extra dimension to the input x on the given axis.
MindSpore: MindSpore API implements the same function as TensorFlow, and only the parameter names are different.
Categories | Subcategories | TensorFlow | MindSpore | Differences |
---|---|---|---|---|
Parameters | Parameter 1 | x | input_x | Same function, different parameter names |
Parameter 2 | axis | axis | - | |
Parameter 3 | name | - | Not involved |
The two APIs achieve the same function and have the same usage.
# TensorFlow
import numpy as np
import tensorflow as tf
x = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], dtype=np.float32)
axis = 1
out = tf.expand_dims (x, axis).numpy()
print(out)
# [[[ 1. 2. 3. 4.]]
# [[ 5. 6. 7. 8.]]
# [[ 9. 10. 11. 12.]]]
# MindSpore
import mindspore
import numpy as np
import mindspore.ops as ops
from mindspore import Tensor
input_params = Tensor(np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]), mindspore.float32)
axis = 1
output = ops.expand_dims(input_params, axis)
print(output)
# [[[ 1. 2. 3. 4.]]
# [[ 5. 6. 7. 8.]]
# [[ 9. 10. 11. 12.]]]
The two APIs achieve the same function and have the same usage.
# TensorFlow
import numpy as np
import tensorflow as tf
x = np.array([[1,1,1]], dtype=np.float32)
axis = 2
out = tf.expand_dims (x, axis).numpy()
print(out)
# [[[1.]
# [1.]
# [1.]]]
# MindSpore
import mindspore
import numpy as np
import mindspore.ops as ops
from mindspore import Tensor
input_params = Tensor(np.array([[1,1,1]]), mindspore.float32)
axis = 2
output = ops.expand_dims(input_params, axis)
print(output)
# [[[1.]
# [1.]
# [1.]]]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。