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.]
  • 相关阅读:
    [SDOI2008]递归数列
    [SCOI2008]奖励关
    [SCOI2010]幸运数字
    [ZJOI2007]矩阵游戏
    [HAOI2006]旅行
    [ZJOI2008]泡泡堂
    [BZOJ1800][Ahoi2009]fly 飞行棋
    [POJ2288]Islands and Bridges
    [LUOGU] 3959 宝藏
    [BZOJ]1029: [JSOI2007]建筑抢修
  • 原文地址:https://www.cnblogs.com/weizhen/p/8451500.html
Copyright © 2011-2022 走看看