python - 如何使用 Tensorflow 找到值的立方根?
问题描述
我尝试了以下方法:
>>> 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
是用于平方根的。但是如果我需要一个数字的立方根,我如何用 tensorflow 计算它?
解决方案
请试试这个:
>>> 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>
猜猜问题出在数据类型上。
推荐阅读
- sql - 数值数据类型和小数
- wordpress - Elementor Page Builder Plugin 是否适用于多站点 wordpress?
- json - 如何访问 select 语句中的特定 json 字段以及 count 函数?
- typescript - node_modules/@types/node d.ts 文件出现问题
- ios - 如何快速找到 UIButton 的正确位置?
- azure-devops - 使用 Azure DevOps 作为数据源的 Power BI 报告停止运行
- jquery - Ajax 请求到达控制器 laravel 时为空
- bash - 无法从终端运行 PyPi 可读性包
- opc - 启动UA-ModelCompiler时出现问题
- c++ - 我的 int main() 中出现堆栈溢出错误