tensorflow定义神经网络损失函数MSE

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,如果不加轴的话,返回的是一个数