1、绝对值函数keras.ops.absolute()
#定义一个张量
x = keras.ops.convert_to_tensor([-10.2, 11.2])
xAbs = keras.ops.absolute(x)
print(xAbs)
打印结果:
array([10.2, 11.2], dtype=float32)
2、加法函数keras.ops.add(x1,x2)
示例1
#定义两个张量分别为x1、x2
x1 = keras.ops.convert_to_tensor([1, 4])
x2 = keras.ops.convert_to_tensor([5, 6])
x3 = keras.ops.add(x1, x2)
print(x3)
打印结果:
array([6, 10], dtype=int32)
示例2
#定义两个不同形状的张量x1、x2
x1 = keras.ops.convert_to_tensor(
[[5, 4],
[5, 6]]
)
x2 = keras.ops.convert_to_tensor([5, 6])
x3 = keras.ops.add(x1, x2)
print(x3)
打印结果:
array([[10 10]
[10 12]], shape=(2, 2), dtype=int32)
3、append函数keras.ops.append(x1, x2, axis=None)
#定义两个张量
x1 = keras.ops.convert_to_tensor([1, 2, 3])
x2 = keras.ops.convert_to_tensor([[4, 5, 6], [7, 8, 9]])
#x1和x2必须具备兼容的形状
x3 = keras.ops.append(x1, x2)
print(x3)
打印结果:
array([1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int32)