zoukankan      html  css  js  c++  java
  • 127、TensorFlow 计算图执行(二)

    import tensorflow as tf
    # Define a placeholder that expects a vector of three floating-point values
    # and a computation that depends on it
    x = tf.placeholder(tf.float32, shape=[3])
    y = tf.square(x)
    
    with tf.Session() as sess:
        # Feeding a value changes the result that is returned when you evaluate y
        print(sess.run(y, {x:[1.0, 2.0, 3.0]}))  # => "[1.0,4.0,9.0]"
        print(sess.run(y, {x:[0.0, 0.0, 5.0]}))  # => "[0.0,0.0,25.0]"
        
        # Raises "tf.errors.InvalidArgumentError" , because you must feed a value for
        # a 'tf.placeholder()' when evaluating a tensor that depends on it
        sess.run(y)
        
        # Raise 'ValueError', because the shape of 37.0 does not match the shape
        # of placeholder x
        sess.run(y, {x:37.0})

    下面是输出的结果:

    2018-02-17 11:11:35.215329: 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
    [ 1.  4.  9.]
    [  0.   0.  25.]
  • 相关阅读:
    P2519 [HAOI2011]problem a
    P1084 疫情控制
    P1941 飞扬的小鸟
    NOIP填坑计划
    P2831 愤怒的小鸟
    AGC 16 D
    P3960 列队
    Python3爬虫相关软件,库的安装
    软件理论基础—— 第一章命题逻辑系统L
    软件理论基础——导论
  • 原文地址:https://www.cnblogs.com/weizhen/p/8451500.html
Copyright © 2011-2022 走看看