Difference between tf.matmul() and tf.multiply()

1.tf.multiply() The corresponding elements in the two matrices are multiplied by each other

Format: tf.multiply(x, y, name=None) 
Parameters: 
x: A tensor of type: half, float32, float64, uint8, int8, uint16, int16, int32, int64, complex64, complex128. 
y: A tensor of the same type as tensor x.  
Return value: x * y element-wise.  
Note: 
(1) Multiply This function implements element-level multiplication, that is, the two multiplied elements are multiplied separately, not matrix multiplication, pay attention to tf.matmul the difference. 
(2) The two multiplied numbers must have the same data type, otherwise an error will be reported.

2.tf.matmul() multiplies matrix a by matrix b, resulting in a*b.

Format: tf.matmul(a, b, transpose_a=False, transpose_b=False, adjoint_a=False, adjoint_b=False, a_is_sparse=False, b_is_sparse=False, name=None) 
Parameters: 
a: a type of float16, float32, float64 , int32, complex64, complex128 Tensor with tensor rank > 1. 
b: a tensor of the same type as tensor a. 
transpose_a: If true, a is transposed before multiplication. 
transpose_b: If true, b is transposed before multiplication. 
adjoint_a: If true, a is conjugated and transposed before multiplication. 
adjoint_b: If true, b is conjugated and transposed before multiplication. 
a_is_sparse: If true, a will be treated as a sparse matrix. 
b_is_sparse: If true, b will be treated as a sparse matrix. 
name: The name of the operation (optional parameter) 
Return value: A tensor of the same type as tensor a and tensor b and the innermost matrix is ​​the product of the corresponding matrices in a and b. 
Note: 
(1) The input must be a matrix (or a tensor with tensor rank > 2, representing a batch of matrices), and it must have matching matrix dimensions after transposition. 
(2) Both matrices must be of the same type. The supported types are as follows: float16, float32, float64, int32, complex64, complex128. 
throws an error: 
ValueError: if transpose_a and adjoint_a, or transpose_b and adjoint_b are both set to true

 

Program example:

 

 

operation result: 

write picture description here

Note: In the world of TensorFlow, the definition and initialization of variables are separated, and all assignments and calculations of graph variables must be performed through the run of tf.Session. You should use tf.global_variables_initializer when you want to collectively initialize all graph variables.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325235638&siteId=291194637