#定义简单的矩阵 constant是定义常量
improt tensorflow as tf
tensorA = tf.constant([[1,2],[3,4]],dtype = tf.float32)
tensorB = tf.constant([[5,6],[7,8]],dtype = tf.float32)
#矩阵相乘
tensorMatmul = tf.matmul(tensorA,tensorB)
等价于tensorA*tensorB
#矩阵相加
tensorAdd = tf.add(tensorA,tensorB)
等价于tensorA+tensorB
#矩阵相除
tensorDivide = tf.divide(tensorA,tensorB)
等价于tensorA/tensorB
#矩阵相减
tensorSubtract = tf.subtract(tensorA,tensorB)
等价于tensorA-tensorB
TensorFlow 在进行四则运算时,一定要求各个 Tensor 数据类型、维度必须一致。