import numpy as np
import tensorflow as tf

y_pred = np.array([[1],
                   [2],
                   [3]],dtype=np.float32)
y_real = np.array([[1],
                   [1],
                   [1]])
    
bias = np.array([1,2,3,4],dtype=np.float32)

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    Input = tf.reduce_mean(tf.square(y_pred-y_real))
# =============================================================================
#     tf.square(y_pred-y_real)
#     [[0]
#      [1]
#      [4]]
# =============================================================================   
    result = sess.run(Input) 
    print(result)
#返回1.6666666666666667,如果不加轴的话,返回的是一个数

相关文章:

  • 2021-10-31
  • 2022-01-27
  • 2021-10-15
  • 2021-10-02
  • 2021-09-09
  • 2021-05-09
  • 2021-12-10
  • 2021-05-21
猜你喜欢
  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
  • 2021-11-30
  • 2022-01-24
  • 2021-10-21
  • 2021-11-27
相关资源
相似解决方案