TensorFlow 基础

import tensorflow as tf
X = tf.constant ([[1., 2.], [3., 4.]])
y = tf.constant ([[1.], [2.]])
w = tf.Variable (initial_value=[[1.], [2.]])
b = tf.Variable (initial_value=1.)
with tf.GradientTape () as tape:
    L = tf.reduce_sum (tf.square (tf.matmul (X, w) + b - y))
w_grad, b_grad = tape.gradient (L, [w, b])        # 计算 L (w, b) 关于 w, b 的偏导数
print (L, w_grad, b_grad)

上面这段执行完后报错如下,请赐教如何修改,谢谢。

2020-04-26 16:31:11.896090: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Traceback (most recent call last):
  File "E:/[RemoteSync]/Shared/PycharmProjects/test/src/03.partial_derivative.py", line 8, in <module>
    L = tf.reduce_sum (tf.square (tf.matmul (X, w) + b - y))
  File "C:\Users\demo\AppData\Local\conda\conda\envs\tf2\lib\site-packages\tensorflow_core\python\util\dispatch.py", line 180, in wrapper
    return target (*args, **kwargs)
  File "C:\Users\demo\AppData\Local\conda\conda\envs\tf2\lib\site-packages\tensorflow_core\python\ops\math_ops.py", line 1595, in reduce_sum
    _ReductionDims (input_tensor, axis))
  File "C:\Users\demo\AppData\Local\conda\conda\envs\tf2\lib\site-packages\tensorflow_core\python\ops\math_ops.py", line 1473, in _ReductionDims
    return constant_op.constant (np.arange (rank, dtype=np.int32))
  File "C:\Users\demo\AppData\Local\conda\conda\envs\tf2\lib\site-packages\tensorflow_core\python\framework\constant_op.py", line 258, in constant
    allow_broadcast=True)
  File "C:\Users\demo\AppData\Local\conda\conda\envs\tf2\lib\site-packages\tensorflow_core\python\framework\constant_op.py", line 266, in _constant_impl
    t = convert_to_eager_tensor (value, ctx, dtype)
  File "C:\Users\demo\AppData\Local\conda\conda\envs\tf2\lib\site-packages\tensorflow_core\python\framework\constant_op.py", line 96, in convert_to_eager_tensor
    return ops.EagerTensor (value, ctx.device_name, dtype)
ValueError: Attempt to convert a value (0) with an unsupported type (<class 'numpy.int32'>) to a Tensor.

Process finished with exit code 1