创建秩为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. 微信小程序这一块(续)

    1.设置头部的信息 通过wx.setNavigationBarTitle 详情见:https://developers.weixin.qq.com/miniprogram/dev/api/ui/nav ...

  2. pdo getLastInertID()无结果

    该函数只返回具有自增约素的表, 不然返回0. 使用exec()得到的是受影响的行数.

  3. smbmount - 装载一个 smbfs 文件系统

    总览 SYNOPSIS smbmount {service} {mount-point} [-o options] 描述 DESCRIPTION smbmount 可以装载一个Linux SMB文件系 ...

  4. 初学Java 九九乘法表

    public class MultiplicationTable { public static void main(String[] args) { System.out.println(" ...

  5. Codeforces Round #554 (Div. 2) C.Neko does Maths (gcd的运用)

    题目链接:https://codeforces.com/contest/1152/problem/C 题目大意:给定两个正整数a,b,其中(1<=a,b<=1e9),求一个正整数k(0&l ...

  6. 【Leetcode周赛】从contest-121开始。(一般是10个contest写一篇文章)

    Contest 121 (题号981-984)(2019年1月27日) 链接:https://leetcode.com/contest/weekly-contest-121 总结:2019年2月22日 ...

  7. ltp-ddt nand_perf_ubifs_w_cpuload

    NAND_M_PERF_UBIFS_CPU_LOAD source 'common.sh';/opt/ltp/runltp -f ddt/nand_perf_ubifs -s "NAND_S ...

  8. ubuntu 安装apache2 二进制包

    官方安装教程  http://httpd.apache.org/docs/2.4/install.html 一.下载安装包 进入https://httpd.apache.org/download.cg ...

  9. hdu 4619 Warm up 2 (二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4619 题意: 平面上有一些1×2的骨牌,每张骨牌要么水平放置,要么竖直放置,并且保证同方向放置的骨牌不 ...

  10. String、StringBuffer、StringBuilder详解

    String类 字符串广泛应用在java编程中,String类在java.lang包中,String类是final修饰的,不能被继承,String类对象创建后不能修改,由0或多个字符组成,包含在一对双 ...