矩阵相乘:
tf.matmul(x,y) 矩阵相乘:A 的shape为(2,3),B的shape为(3,4),则结果shape为(2,4)
矩阵和矩阵元素的操作:
矩阵元素相加:
tf.math.add(x,y)等价于x + y
矩阵相减:
tf.math.subtract(x,y)等价于x-y
矩阵元素相乘:
tf.math.multiply(x,y) 等价于:x*y
矩阵元素相除:
tf.math.devide(x,y)等价于x/y
矩阵元素绝对值:
tf.math.abs(x)
比较操作:
tf.math.maximum(a,b)
tf.math.minimum(a,b)
tf.math.equal(a,b)
tf.math.equal(a,3)
tf.math.equal(3,3)
tf.math.equal(a,a)
tf.math.greater(a,3)
tf.math.greater_equal(a,3)
矩阵和数字的操作:
矩阵元素数乘:3*a 等价于a*3
矩阵元素数加:3+a 等价于a+3
矩阵元素数减:3-a等价于a-3
矩阵元素数除a/3,3/a
矩阵元素的类似计算操作都在tf.math包中
特别的:
最大值:
tf.math.reduce_max(a,axis=1,keepdims=True)将最后一维最大值,可以选择保留维度或压缩掉
最大值对应的位置indices:
tf.argmax(predict_result["logits"],axis=-1)将最后一维进行压缩求最大值对应的position
求top_k最大值:
tf.math.top_k(x)
tf.where操作:
将向量中大于0.5的设置为1,小于0.5的设置为0
tf.where(A>0.5,x=1,y=0)表示将A>0.5中条件为true的元素设置为x,为false的设置为y