美文网首页
02-TensorFlow常用函数

02-TensorFlow常用函数

作者: kang_james | 来源:发表于2019-06-28 18:42 被阅读0次

1、tf.matmul(matrix1,matrix2):向量的乘积

代码示例:

import tensorflow as tf
# 1x2的矩阵
matrix1 = tf.constant([[3,3]]) #创建一个常量
#2 x 1的矩阵
matrix2 = tf.constant([[2],[2]])
product = tf.matmul(matrix1,matrix2)

with tf.Session() as sess:
  print(sess.run(product))

计算结果:

[[12]]

2、tf.add(state,one):求和 与 tf.assign(state,new_value):赋值

代码示例:

import tensorflow as tf
#定义一个变量,并初始化
state = tf.Variable(0,name='counter')
#定义一个值为1常量
one = tf.constant(1)
#求和
new_value = tf.add(state,one)
#重新赋值给state
updata = tf.assign(state,new_value)
#初始化变量
init = tf.global_variables_initializer()
with tf.Session() as sess:
  sess.run(init)
  for step in range(3):
    print(sess.run(updata))

运行结果:

1
2
3

3.tf.placeholder(tf.float32):指定站位 与 tf.multiply(input1, input2):向量內积(对应位置相乘)

代码实例:

import tensorflow as tf
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)
output = tf.multiply(input1,input2)

with tf.Session() as sess:
  print(sess.run(output,feed_dict={input1:[3.,2.], input2:[5.,2.]}))

运行结果:

[15.  4.]

这一部分后续继续更新.....................

相关文章

  • 02-TensorFlow常用函数

    1、tf.matmul(matrix1,matrix2):向量的乘积 代码示例: 计算结果: 2、tf.add(s...

  • php-常用函数

    常用函数 常用函数: 数组常用函数

  • excel 常用快捷键及函数

    1.常用快捷键 2.常用函数 ①零件函数 日期函数 文本函数 统计函数 随机函数 ②if函数

  • 函数进阶_2

    目录 常用内置函数 匿名函数 高阶函数 闭包 装饰器 1. 常用内置函数 1.1 range()函数 语法:ran...

  • MySQL基本使用

    函数 常用函数 数学函数 字符串函数 日期函数

  • C++常用库函数

    1.常用数学函数 #include 2.常用字符串处理函数 #include 3.其他常用函数 ...

  • 机器学习

    常用激活函数(激励函数) Sigmoid函数 Relu函数

  • python常用时间函数

    常用函数 日常写代码,经常用到时间相关的函数,以下整理了python常用的时间函数: 执行结果 此外datatim...

  • c++ 7、字符串

    1、字符串常用函数(原生) 2、字符串常用函数(扩展)

  • iOS-GCD常用函数和栅栏函数

    GCD常用函数 GCD栅栏函数

网友评论

      本文标题:02-TensorFlow常用函数

      本文链接:https://www.haomeiwen.com/subject/ikwecctx.html