Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

tensorlfow math.log() 是以自然常数e为底 转化为以2为底:
根据对数换底公式:

log2

∴ loge(4)/loge(2) = log2(4) = 2

代码实例:

import tensorflow as tf
x = tf.math.log(4.)/tf.math.log(2.)

Out:

<tf.Tensor: shape=(), dtype=float32, numpy=2.0>

效果等同于 numpy log2(4)

import numpy as np

np.log2(4)

Out:

2.0