你的
Tout
必须是
(tf.float64,tf.float64)
而不是
[tf.float64]
eigval = py_func(calc_second_eigval,
[x],
(tf.float64,tf.float64),
name=name,
grad=_SecondEigValGrad)
这是一个正在运行的演示
import tensorflow as tf
# Function in python
def dummy(x):
return [x,x]
print(dummy([1.0,2.0]))
tf_fun = tf.py_func(dummy,[[1.0,2.0]],(tf.float32,tf.float32))
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(sess.run(tf_fun))