我尝试了以下方法:
>>> import tensorflow as tf
>>> tf.enable_eager_execution()
>>> tf.math.pow(3,3)
2019-05-06 16:05:51.508296: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
<tf.Tensor: id=3, shape=(), dtype=int32, numpy=27>
>>> tf.math.pow(9,(1/3))
<tf.Tensor: id=7, shape=(), dtype=int32, numpy=1>
>>> tf.math.pow(27,(1/3))
<tf.Tensor: id=11, shape=(), dtype=int32, numpy=1>
>>> tf.math.pow(27,0.3)
<tf.Tensor: id=15, shape=(), dtype=int32, numpy=1>
>>> tf.math.pow(4,0.5)
<tf.Tensor: id=19, shape=(), dtype=int32, numpy=1>
>>> tf.math.pow(4,1/2)
<tf.Tensor: id=23, shape=(), dtype=int32, numpy=1>
我知道sqrt
用于平方根。但是,如果我需要一个数字的立方根,该如何使用张量流来计算它?
答案 0 :(得分:1)
请尝试以下操作:
>>> import tensorflow as tf
>>> tf.enable_eager_execution()
>>> tf.math.pow(27.0,1.0/3.0)
2019-05-06 16:22:39.403646: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
<tf.Tensor: id=3, shape=(), dtype=float32, numpy=3.0>
猜猜问题出在数据类型上。
答案 1 :(得分:1)
如果要查看结果,可以使用InteractiveSession
和eval
:
import tensorflow as tf
tf.InteractiveSession()
tf.pow(27.0,1/3).eval()