在tensorflow中使用exp,sin,cos函数获取错误

时间:2016-05-04 12:24:35

标签: python-2.7 tensorflow

import numpy as np
import tensorflow as tf

b = tf.constant(2)

**sess.run(tf.exp(b))**

错误讯息:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/aravindp/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 340, in run
    run_metadata_ptr)
  File "/home/aravindp/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 564, in _run
    feed_dict_string, options, run_metadata)
  File "/home/aravindp/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 637, in _do_run
    target_list, options, run_metadata)
  File "/home/aravindp/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 659, in _do_call
    e.code)
**tensorflow.python.framework.errors.InvalidArgumentError: No OpKernel was registered to support Op 'Exp' with these attrs**
     [[Node: Exp = Exp[T=DT_INT32](Const_1)]]
Caused by op u'Exp', defined at:
  File "<stdin>", line 1, in <module>
  File "/home/aravindp/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_math_ops.py", line 505, in exp
    return _op_def_lib.apply_op("Exp", x=x, name=name)
  File "/home/aravindp/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/ops/op_def_library.py", line 655, in apply_op
    op_def=op_def)
  File "/home/aravindp/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2154, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/home/aravindp/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1154, in __init__
    self._traceback = _extract_stack()

>>> 

1 个答案:

答案 0 :(得分:1)

试试这个:

import tensorflow as tf

b = tf.constant(2.)
sess = tf.Session()
print (sess.run(tf.exp(b)))