zoukankan      html  css  js  c++  java
  • 107、TensorFlow变量(三)

    创建秩为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:	f_jenkinsworkspace
    el-winMwindowsPY35	ensorflowcoreplatformcpu_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:	f_jenkinsworkspace
    el-winMwindowsPY35	ensorflowcoreplatformcpu_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:	f_jenkinsworkspace
    el-winMwindowsPY35	ensorflowcoreplatformcpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
    4
  • 相关阅读:
    深度学习模型参数计算
    keras多输出多输出示例(keras教程一)
    keras可视化报错:OSError: `pydot` failed to call GraphViz.Please install GraphViz问题解决
    git版本管理,git tag
    python封装自己的模块,pip install安装到python环境
    如何理解Virtual DOM
    使用 Hbuilder 连接手机调试移动端项目
    js 常用排序
    博客漂浮的小人
    开发者必备Linux命令
  • 原文地址:https://www.cnblogs.com/weizhen/p/8450532.html
Copyright © 2011-2022 走看看