我有一个数组:[1,4,-10,3,5]。我尝试使用该数组创建220940
个权重。
在训练之后,我将重量打印为:
570772~CORPORATE BANK TRANSIT OF KENTUCKY INC~3157 HIGHWAY 64 SUITE 100~EADS~TN~38028~Y
384767~MILLER FARMS TRANS LLC~1103 COURT ST~BEDFORD~IA~50833~Y
986150~R G S TRUCKING LTD~1765 LOMBARDIE DRIVE~QUESNEL~BC~V2J 4A8~Y
1012987~DONALD LARRY KIVETT~4509 LANSBURY RD~GREENSBORO~NC~27406-4509~Y
735308~ALZEY EXPRESS INC~2244 SOUTH GREEN STREET~HENDERSON~KY~42420~Y
870337~RIES FARMS~1613 255TH AVENUE~EARLVILLE~IA~52057~Y
148428~P R MASON & SON LLC~HWY 70 EAST~WILLISTON~NC~28589~Y
220940~TEXAS MOVING CO INC~908 N BOWSER RD~RICHARDSON~TX~75081-2869~N
854042~ARMANDO ORTEGA~6590 CHERIMOYA AVENUE~FONTANA~CA~92337~N
940587~DIAMOND A TRUCKING INC~192285 E COUNTY ROAD 55~HARMON~OK~73832~N
1032455~INTEGRITY EXPRESS LLC~380 OLMSTEAD AVENUE~DEPEW~NY~14043~N
889931~DUNSON INC~33 CR 3581~FLORA VISTA~NM~87415~N
Variable
只是格式为[1,4,-10,3,5]的数组。
我是如何尝试从数组中创建result = sess.run(w)
print(result)
的:
result
显然,这个权重结果是错误的,我花了好几个小时查看文档和SO帖子。如何使用该数组创建Variable
?
答案 0 :(得分:0)
您不必遍历元素;而是简单地使用整个列表,如:
In [21]: vals = [1, 4, -10, 3, 5]
# create Variable `W`
In [22]: W = tf.Variable(initial_value=vals, name='weights')
# initialize all variables
In [23]: init = tf.global_variables_initializer()
In [24]: with tf.Session() as sess:
...: sess.run(init)
...: print(W.eval())
# prints
[ 1 4 -10 3 5]