Tensorflow common method summary

Matrix multiplication:

tf.matmul(x,y) matrix multiplication: the shape of A is (2,3), the shape of B is (3,4), and the result shape is (2,4)

Operations on matrices and matrix elements:

Add matrix elements:

tf.math.add(x,y) is equivalent to x + y

Matrix subtraction:

tf.math.subtract(x,y) is equivalent to xy

Multiply matrix elements:

tf.math.multiply(x,y) is equivalent to: x*y

Matrix elementwise division:

tf.math.devide(x,y) is equivalent to x/y

Absolute value of matrix elements:

tf.math.abs(x)

Comparison operation:

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)

Operations on matrices and numbers:

Multiplication of matrix elements: 3*a is equivalent to a*3

Adding the number of matrix elements: 3+a is equivalent to a+3

Subtract the number of matrix elements: 3-a is equivalent to a-3

Divide the number of matrix elements by a/3,3/a

Similar computational operations for matrix elements are in the tf.math package

special:

Maximum value:

tf.math.reduce_max(a,axis=1,keepdims=True) will be the maximum value of the last dimension, you can choose to keep the dimension or compress it

The position indices corresponding to the maximum value:

tf.argmax(predict_result["logits"],axis=-1) Compress the last dimension to find the position corresponding to the maximum value

Find the maximum value of top_k:

tf.math.top_k(x)

tf.where operation:

Set the vector greater than 0.5 to 1, and less than 0.5 to 0

tf.where(A>0.5, x=1, y=0) indicates that the element in A>0.5 whose condition is true is set to x, and the element which is false is set to y

Guess you like

Origin blog.csdn.net/sslfk/article/details/129703017