Python 我无法找出编译器报告错误的原因?
错误:InvalidArgumentError(回溯请参见上文):形状不兼容:[2]与[4]Python 我无法找出编译器报告错误的原因?,python,numpy,tensorflow,Python,Numpy,Tensorflow,错误:InvalidArgumentError(回溯请参见上文):形状不兼容:[2]与[4] [[Node:mul=mul[T=DT\u FLOAT,\u device=“/job:localhost/replica:0/task:0/cpu:0”](变量/读取,\u recv\u占位符\u 0)]我想问题就在这里 而不是在W中使用float32 import tensorflow as tf import numpy as np W = tf.Variable([0,3], dtype
[[Node:mul=mul[T=DT\u FLOAT,\u device=“/job:localhost/replica:0/task:0/cpu:0”](变量/读取,\u recv\u占位符\u 0)]我想问题就在这里 而不是在W中使用float32
import tensorflow as tf
import numpy as np
W = tf.Variable([0,3], dtype = tf.float32)
b = tf.Variable([-0.3], dtype = tf.float32)
x = tf.placeholder(tf.float32)
linear_model = W * x + b
y = tf.placeholder(tf.float32)
loss = tf.reduce_sum(tf.square(linear_model - y))
optimizer = tf.train.GradientDescentOptimizer(0.01)
train = optimizer.minimize(loss)
x_train = [1,2,3,4]
y_train = [0,-1,-2,-3]
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
for i in range(1000):
sess.run(train, {x: x_train, y: y_train})
curr_W, curr_b, curr_loss = sess.run([W,b,loss], {x: [1,2,3,4], y: [0,-1,-2,-3]})
print("w: %s, b: %s, loss: %s", curr_W, curr_b, curr_loss)
会的
W = tf.Variable([0,3], dtype = tf.float32)
b = tf.Variable([-0.3], dtype = tf.float32)
你的意思是[0.3]而不是[0,3](有一个逗号)吗?哦,那真的很有用!天哪!这真是一个详细的错误,伙计!
W = tf.Variable([0.3], dtype = tf.float32)
b = tf.Variable([-0.3], dtype = tf.float32)