x = tf.constant([[0.7, 0.9]])与x = tf.constant([0.7, 0.9])
来源:互联网 发布:Ubuntu配置caffe CPU 编辑:程序博客网 时间:2024/05/21 07:56
下面这段代码:
w1 = tf.Variable(tf.random_normal([2,3], stddev=1, seed=1))
w2 = tf.Variable(tf.random_normal([3,1], stddev=1, seed=1))
x = tf.constant([[0.7, 0.9]])
开始写成x = tf.constant([0.7, 0.9]),运行时总是出错:
Traceback (most recent call last):
File "<ipython-input-9-60e968c8a781>", line 1, in <module>
runfile('/home/yong/qx.py', wdir='/home/yong')
File "/home/yong/anaconda2/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 710, in runfile
execfile(filename, namespace)
File "/home/yong/anaconda2/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 93, in execfile
builtins.execfile(filename, *where)
File "/home/yong/qx.py", line 13, in <module>
a = tf.matmul(x, w1)
File "/home/yong/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/math_ops.py", line 1844, in matmul
a, b, transpose_a=transpose_a, transpose_b=transpose_b, name=name)
File "/home/yong/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/gen_math_ops.py", line 1289, in _mat_mul
transpose_b=transpose_b, name=name)
File "/home/yong/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
op_def=op_def)
File "/home/yong/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2632, in create_op
set_shapes_for_outputs(ret)
File "/home/yong/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1911, in set_shapes_for_outputs
shapes = shape_func(op)
File "/home/yong/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1861, in call_with_requiring
return call_cpp_shape_fn(op, require_shape_fn=True)
File "/home/yong/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 595, in call_cpp_shape_fn
require_shape_fn)
File "/home/yong/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 659, in _call_cpp_shape_fn_impl
raise ValueError(err.message)
ValueError: Shape must be rank 2 but is rank 1 for 'MatMul_21' (op: 'MatMul') with input shapes: [2], [2,3].
今天知道了原因,少写了一对括号。
也许,一对括号表示的是列表,两对括号才表示矩阵。矩阵要与矩阵相乘,导致了前面的错误。
- x = tf.constant([[0.7, 0.9]])与x = tf.constant([0.7, 0.9])
- tf.constant学习
- tensorflow学习笔记(2):常量(tf.constant)与变量(tf.Varialbe)
- tf.is_finite(x, name=None)
- tf.equal(x, y, name=None)
- tf.cast(x,dtype,name=None )
- Tensorlow 中文API:tf.zeros() tf.ones()tf.fill()tf.constant()
- tensorflow tf.logical_and(True, False) tf.logical_not(x, name=None)
- Angularjs1.x 中的 constant, value
- tensorflow tf.equal(x, y, name=None)
- Constant
- constant
- python np.mean(axis) tf.squeeze(x)
- TensorFlow 辨异 —— tf.add(a, b) 与 a+b(tf.assign 与 =)、tf.nn.bias_add 与 tf.add
- TF
- tf
- tf.truncated_normal与tf.random_normal
- tf.InteractiveSession()与tf.Session()
- 属性动画
- ARM全解析 ARM8/ARM7/A9/A15等区别
- 蘑菇街搜索与推荐架构
- .reserve后缀勒索病毒最新变种通报--by达康勒索病毒解密中心
- QoS配置与管理——3
- x = tf.constant([[0.7, 0.9]])与x = tf.constant([0.7, 0.9])
- get提交和post提交的区别
- 创建订单
- Python操作SQLite/MySQL/LMDB/LevelDB
- Linux之HA高可用集群的基础概念总结
- Java代码使用ffmpeg视频按帧存储
- 使用jquery动态添加导航页卡和标题
- 京东订单
- Bean