tf.subtract()

参考官方文档

format:subtract(x, y, name=None)

Args:
      x: A `Tensor`. Must be one of the following types: `half`, `float32`, `float64`, `int32`, `int64`, `complex64`, `complex128`.
      y: A `Tensor`. Must have the same type as `x`.(也是强调x,y两个参数类型必须相同)

      name: A name for the operation (optional).

Returns:
      A `Tensor`. Has the same type as `x`.x - y element-wise.(返回的数据类型与x相同,且是x-y的操作是元素级别的,具体看栗子)

栗子

import tensorflow as tf  
#两个矩阵相减
x=tf.constant([[1,2],[2,1]])  
y=tf.constant([[1,1],[1,2]])
z=tf.subtract(x,y)

#一个矩阵减一个数
x1=tf.constant([[1,2],[2,1]])  
y1=tf.constant(2)
z1=tf.subtract(x1,y1)

#一个数减一个矩阵
x2=tf.constant(2)
y2=tf.constant([[1,2],[2,1]])
z2=tf.subtract(x2,y2)

with tf.Session() as sess:
    z_v,z1_v=sess.run([z,z1])
    print('z = \n%s'%(z_v))
    print('z1 = \n%s'%(z1_v))
结果

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值