0
我在使用tensorflow並且正在用於學校項目。在這裏,我試圖創建一個房屋標識符,我在一張Excel表格上創建了一些數據,將其轉換爲一個csv文件,然後測試數據是否會被讀取。數據被讀取,但是當我進行矩陣乘法並且說...時,它會產生多個錯誤。「ValueError:形狀必須是等級2,但是'MatMul'(op:'MatMul')的等級爲0,輸入形狀爲:[] ,[1,1]。「非常感謝!矩陣乘法不起作用 - Tensorflow
import tensorflow as tf
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
filename = dir_path+ "\House Price Data .csv"
w1=tf.Variable(tf.zeros([1,1]))
w2=tf.Variable(tf.zeros([1,1])) #Feature 1's weight
w3=tf.Variable(tf.zeros([1,1])) #Feature 1's weight
b=tf.Variable(tf.zeros([1])) #bias for various features
x1= tf.placeholder(tf.float32,[None, 1])
x2= tf.placeholder(tf.float32,[None, 1])
x3= tf.placeholder(tf.float32,[None, 1])
Y= tf.placeholder(tf.float32,[None, 1])
y_=tf.placeholder(tf.float32,[None,1])
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
with open(filename) as inf:
# Skip header
next(inf)
for line in inf:
# Read data, using python, into our features
housenumber, x1, x2, x3, y_ = line.strip().split(",")
x1 = float(x1)
product = tf.matmul(x1, w1)
y = product + b
它看起來像你正在覆蓋x1變量。 – Aaron
來自csv文件的輸入是我想要的x1 vatiable。非常感謝你的幫助! – anonymous
我在調試時將x1用作測試示例 – anonymous