创建秩为1的张量

# create a rank1 tensor object
import tensorflow as tf
mystr = tf.Variable(["Hello"], tf.string)
cool_numbers = tf.Variable([3.14159, 2.71828], tf.float32)
first_primes = tf.Variable([2, 3, 5, 7, 11], tf.int32)
its_very_complicated = tf.Variable([12.3 - 4.85j, 7.5 - 6.23j], tf.complex64)
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
print(sess.run(mystr))
print(sess.run(cool_numbers))
print(sess.run(first_primes))
print(sess.run(its_very_complicated))

下面是上面的结果:

2018-02-16 21:31:32.599557: I C:\tf_jenkins\workspace\rel-win\M\windows\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
[b'Hello']
[ 3.14159012 2.71828008]
[ 2 3 5 7 11]
[ 12.3-4.85j 7.5-6.23j]

创建秩为二的张量

# create rank2 tensor
import tensorflow as tf
mymat = tf.Variable([[7], [11]], tf.int16)
myxor = tf.Variable([[False, True], [True, False]], tf.bool)
linear_squares = tf.Variable([[4], [9], [16], [25]], tf.int32)
squarish_squares = tf.Variable([ [4, 9], [16, 25] ], tf.int32)
rank_of_squares = tf.rank(linear_squares)
mymatC = tf.Variable([[7], [11]], tf.int32)
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
print(sess.run(rank_of_squares))

下面是秩为二的张量的结果:

2018-02-16 21:33:53.407399: I C:\tf_jenkins\workspace\rel-win\M\windows\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2

创建维度更高的张量

# create higher rank tensors ,
# consist of an n-dimensional array
import tensorflow as tf
my_image = tf.zeros([10, 299, 299, 3])
# Getting a tf.Tensor object's rank
r = tf.rank(my_image)
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
print(sess.run(r))

下面是维度更高的张量的结果:

2018-02-16 21:34:57.278721: I C:\tf_jenkins\workspace\rel-win\M\windows\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
4

107、TensorFlow变量(三)的更多相关文章

  1. tensorflow变量-【老鱼学tensorflow】

    在程序中定义变量很简单,只要定义一个变量名就可以,但是tensorflow有点类似在另外一个世界,因此需要通过当前的世界中跟tensorlfow的世界中进行通讯,来告诉tensorflow的世界中定义 ...

  2. tensorflow变量

    tensorflow变量: 1.神经网络中的参数权重,偏置等可以作为张量保存到tensorflow的变量中 2.tensorflow变量必须被初始化 3.可被保存到文件中,下次使用重新加载即可 ten ...

  3. tensorflow变量的使用(02-2)

    import tensorflow as tf x=tf.Variable([1,2]) a=tf.constant([3,3]) sub=tf.subtract(x,a) #增加一个减法op add ...

  4. TF Boys (TensorFlow Boys ) 养成记(三): TensorFlow 变量共享

    上次说到了 TensorFlow 从文件读取数据,这次我们来谈一谈变量共享的问题. 为什么要共享变量?我举个简单的例子:例如,当我们研究生成对抗网络GAN的时候,判别器的任务是,如果接收到的是生成器生 ...

  5. Tensorflow 变量的共享

    https://github.com/chenghuige/tensorflow-exp/blob/master/examples/sparse-tensor-classification/ tens ...

  6. 神经网络参数与TensorFlow变量

    在TensorFlow中变量的作用是保存和更新神经网络中的参数,需要给变量指定初始值,如下声明一个2x3矩阵变量 weights =tf.Variable(tf.random_normal([2,3] ...

  7. Java学习笔记之linux配置java环境变量(三种环境变量)

    0x00 压安装jdk 在shell终端下进入jdk-6u14-linux-i586.bin文件所在目录, 执行命令 ./jdk-6u14-linux-i586.bin 这时会出现一段协议,连继敲回车 ...

  8. tensorflow变量作用域(variable scope)

    举例说明 TensorFlow中的变量一般就是模型的参数.当模型复杂的时候共享变量会无比复杂. 官网给了一个case,当创建两层卷积的过滤器时,每输入一次图片就会创建一次过滤器对应的变量,但是我们希望 ...

  9. TensorFlow笔记三:从Minist数据集出发 两种经典训练方法

    Minist数据集:MNIST_data 包含四个数据文件 一.方法一:经典方法 tf.matmul(X,w)+b import tensorflow as tf import numpy as np ...

随机推荐

  1. flask为blueprint增加error_handler

    对整个app增加errorhandler,只需如下: @portal_page.errorhandler(404) def page_not_found(error): cats = Category ...

  2. webpack2.0 基本使用

    webpack是一款前端模块打包工具, 它的出现是由于现代web开发越来越复杂,如果还是像原来那样把所有的js代码都写到一个文件中,维护非常困难.而解决复杂化的方法通常是分而治之,就是把复杂化的东西进 ...

  3. [Codeforces 464E] The Classic Problem(可持久化线段树)

    [Codeforces 464E] The Classic Problem(可持久化线段树) 题面 给出一个带权无向图,每条边的边权是\(2^{x_i}(x_i<10^5)\),求s到t的最短路 ...

  4. 进程池和multiprocess.Pool模块

    一.为什么要有进程池 首先,创建进程需要消耗时间,销毁进程也需要时间.其次,即使开启了成千上万的进程,操作系统也不能让它们同时执行,这样反而会影响程序的效率.因此我们不能无限制的根据任务开启或者结束进 ...

  5. Tensorflow机器学习入门——MINIST数据集识别

    参考网站:http://www.tensorfly.cn/tfdoc/tutorials/mnist_beginners.html #自动下载并加载数据 from tensorflow.example ...

  6. TCL环境检查

    set w [open 1.txt w+] foreach a [info var] { if { [llength [array name $a]]==0 } { puts $w $a:[set $ ...

  7. Mybatis-技术专区-中的条件查询createCriteria example里面的条件

    之前用Mybatis框架反向的实体,还有实体里面的Example,之前只是知道Example里面放的是条件查询的方法,可以一直不知道怎么用,到今天才开始知道怎么简单的用. 在我们前台查询的时候会有许多 ...

  8. k3 cloud移动审批提示实体类型BD_TaxRate中不存在名为AmountDigits属性

    原因是由于字段没有正确绑定币别,找到对应的字段并修改绑定币别

  9. MapReduce-WordCountDemo

    /** * @Author: dreamer Q * @Date: 2019/11/4 22:26 * @Version 1.0 * @Discription 使用MapReduce 开发 WordC ...

  10. BZOJ-2337 XOR和路径(HNOI2011)概率DP+概率的线性叠加

    题意:给出n个点和m条边,每条边有权值wi,从1出发,每次等概率选一条出边走,直到终点n停止,得到的值是路径所有边的异或和.问异或和期望. 解法:这道题非常有意思!首先比较直观的想法就是dp[x]代表 ...