zoukankan      html  css  js  c++  java
  • tensorflow基本常用操作

    根据之前学习的基础之后,可以利用所学知识简单的做一个循环操作。

    递增输出0到3:

    import numpy as np
    from numpy import float32
    tf.compat.v1.disable_eager_execution()#保证sess.run()能够正常运行
    a=3
    w = tf.zeros([3,4],float32)
    x = tf.range(3,18,3)
    y=tf.zeros_like(x)
    h=tf.ones([1,2],float32)
    init = tf.compat.v1.global_variables_initializer()
    with tf.compat.v1.Session() as sess:
        sess.run(init)
        print(w.eval())
        print(x.eval())
        print(y.eval())
        print(h.eval())

    还学习到了tensorflow的简单定义矩阵变量的方法:

    import numpy as np
    from numpy import float32
    tf.compat.v1.disable_eager_execution()#保证sess.run()能够正常运行
    a=3
    w = tf.zeros([3,4],float32)#创建3行4列,值均为0的矩阵
    x = tf.range(3,18,3)#从3到18间隔为3的矩阵序列(不包含18)
    y=tf.zeros_like(x)#创建与x同列同行的值为0的矩阵
    h=tf.ones([1,2],float32)#创建1行2列,值均为1的矩阵
    init = tf.compat.v1.global_variables_initializer()
    with tf.compat.v1.Session() as sess:
        sess.run(init)
        print(w.eval())
        print(x.eval())
        print(y.eval())
        print(h.eval())

     在tensorflow中定义变量类型时由于兼容性最好使用float32,因为无论gpu还是cpu都可以使用flaot32,减少错误的出现

  • 相关阅读:
    Lucas定理及其应用
    HDU 5044 TREE
    HDU 5033 Building
    Codeforces Round #238 (Div. 1)
    hdu 4878 ZCC loves words AC自动机+中国剩余定理+快速幂
    HDU 5015 233 Matrix
    HDU 5008 Boring String Problem
    ZOJ 3817 Chinese Knot
    使用AutoMapper
    多租户概念以及FreeLink多租户设计思想
  • 原文地址:https://www.cnblogs.com/yangxionghao/p/14330845.html
Copyright © 2011-2022 走看看