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)

参数:

a 一个类型为 float16, float32, float64, int32, complex64, complex128 且张量秩 > 1 的张量
b  一个类型跟张量a相同的张量
transpose_a 如果为真, a则在进行乘法计算前进行转置
transpose_b 如果为真, b则在进行乘法计算前进行转置 
adjoint_a 如果为真, a则在进行乘法计算前进行共轭和转置
adjoint_b 如果为真, b则在进行乘法计算前进行共轭和转置
a_is_sparse 如果为真, a会被处理为稀疏矩阵
b_is_sparse 如果为真, b会被处理为稀疏矩阵

a,b的维数必须相同

import numpy as np
import tensorflow as tf
X = np.array([[1,2],
        [2,2],
        [3,2]])
W = np.array([[3,1,1,4],
        [3,1,1,4]])
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    Input = tf.matmul(X,W)
    result = sess.run(Input)
    print(result)
[[ 9 3 3 12]
 [12 4 4 16]
 [15 5 5 20]]
b在神经网络中一般用作权重矩阵,shape=[x,y],x为前一层神经网络的神经元数量,y为后一层神经网络的神经元数量
下面演示加上偏置bias,偏置采用以为数组,长度为后一层神经网络的神经元数量
import numpy as np
import tensorflow as tf
 
X = np.array([[1,2],[2,2],[3,2]]) 
W = np.array([[3,1,1,4],[3,1,1,4]]) 
bias = np.array([1,2,3,4]) 
with tf.Session() as sess:
  sess.run(tf.global_variables_initializer())
  Input = tf.matmul(X,W) + bias
  result = sess.run(Input)
  print(result)
[[10 5 6 16]
[13 6 7 20]
[16 7 8 24]]

tf.multiply(x, y, name=None) ,两个矩阵中对应元素各自相乘,最后返回数据的维数以最多维数据的维数相同

import numpy as np
import tensorflow as tf a = np.array([[1,2],
[2,3],
[3,4]])
b= np.array([2,3]) with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
Input = tf.multiply(a,b)
result = sess.run(Input)
print(result)

[[ 2 6]
 [ 4 9]
 [ 6 12]]

tf.matmul函数和tf.multiply函数的更多相关文章

  1. tf.matmul / tf.multiply

    import tensorflow as tfimport numpy as np 1.tf.placeholder placeholder()函数是在神经网络构建graph的时候在模型中的占位,此时 ...

  2. tf.matmul() 和tf.multiply() 的区别

    1.tf.multiply()两个矩阵中对应元素各自相乘 格式: tf.multiply(x, y, name=None) 参数: x: 一个类型为:half, float32, float64, u ...

  3. Tensorflow中multiply()函数与matmul()函数的用法区别

    1.tf.multiply()函数:矩阵对应元素相乘 官网定义: multiply(x,y,name=None) 参数: x: 一个类型为:half, float32, float64, uint8, ...

  4. 深度学习原理与框架-图像补全(原理与代码) 1.tf.nn.moments(求平均值和标准差) 2.tf.control_dependencies(先执行内部操作) 3.tf.cond(判别执行前或后函数) 4.tf.nn.atrous_conv2d 5.tf.nn.conv2d_transpose(反卷积) 7.tf.train.get_checkpoint_state(判断sess是否存在

    1. tf.nn.moments(x, axes=[0, 1, 2])  # 对前三个维度求平均值和标准差,结果为最后一个维度,即对每个feature_map求平均值和标准差 参数说明:x为输入的fe ...

  5. tensorflow笔记3:CRF函数:tf.contrib.crf.crf_log_likelihood()

    在分析训练代码的时候,遇到了,tf.contrib.crf.crf_log_likelihood,这个函数,于是想简单理解下: 函数的目的:使用crf 来计算损失,里面用到的优化方法是:最大似然估计 ...

  6. tensorflow笔记4:函数:tf.assign()、tf.assign_add()、tf.identity()、tf.control_dependencies()

    函数原型: tf.assign(ref, value, validate_shape=None, use_locking=None, name=None)   Defined in tensorflo ...

  7. TensorFlow函数:tf.reduce_sum

    tf.reduce_sum 函数 reduce_sum ( input_tensor , axis = None , keep_dims = False , name = None , reducti ...

  8. TensorFlow函数:tf.lin_space

    函数:tf.lin_space 别名: tf.lin_space tf.linspace lin_space( start, stop, num, name=None ) 参见指南:生成常量,序列和随 ...

  9. TensorFlow函数:tf.ones

    tf.ones 函数 ones( shape, dtype=tf.float32, name=None ) 定义于:tensorflow/python/ops/array_ops.py. 请参阅指南: ...

随机推荐

  1. jquery中使用jsonp

    1 .关于jsonp的原理等,请看下面的文章,说的很明白. http://www.cnblogs.com/dowinning/archive/2012/04/19/json-jsonp-jquery. ...

  2. html5、canval 对 图片的压缩

    let src = this.cropper.getCroppedCanvas().toDataURL('image/jpeg');let can = document.createElement(' ...

  3. Robolectric测试框架使用笔记

    1. 概述 Robolectric(http://robolectric.org/)是一款支持在桌面JVM模拟Android环境的测试框架,通过shadow包下的类来截取view.activity等类 ...

  4. 1.1.4 A+B for Input-Output Practice (V)

    A+B for Input-Output Practice (V) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...

  5. Koa下http代理

    前言 最近做管理后台的重构或者说重做. 至于为什么要重构. 随意的解释: 是原来写的人走了. 客观的解释: 用的人觉得不好用 维护的人员找不到北 再多一点解释: express + ejs的混合编写 ...

  6. API设计风格(RRC、REST、GraphQL、服务端驱动)

    API设计风格(RRC.REST.GraphQL.服务端驱动) Web API设计其实是一个挺重要的设计话题,许多公司都会有公司层面的Web API设计规范,几乎所有的项目在详细设计阶段都会进行API ...

  7. HDU 4632 区间DP 取模

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4632 注意到任意一个回文子序列收尾两个字符一定是相同的,于是可以区间dp,用dp[i][j]表示原字 ...

  8. LeetCode Factorial Trailing Zeroes Python

    Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. 题目意思: n求阶乘 ...

  9. pandas 里面对nan的判断

    不要用math.isnan() pandas里专门有一个函数: age_null = pd.isnull(titanic_survival[‘age’])

  10. Git常用有用命令

    1.git reset --hard <commit_id>   //正真的退回到了<commit_id>状态,git记录个源码都退到那个状态了. 2.git reflog   ...