擅长:python、mysql、java
<p>要使用<code>tensorflow</code>计算数组的中值,可以使用<a href="https://www.tensorflow.org/probability/api_docs/python/tfp/stats/percentile" rel="nofollow noreferrer"><strong>^{<cd2>}</strong></a>函数,因为第50个百分点是中值。</p>
<pre><code>import tensorflow as tf
import tensorflow_probability as tfp
import numpy as np
np.random.seed(0)
x = np.random.normal(3.0, .1, 100)
median = tfp.stats.percentile(x, 50.0, interpolation='midpoint')
tf.Session().run(median)
</code></pre>
<p>上面的代码相当于<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.percentile.html" rel="nofollow noreferrer"><strong>^{<cd3>}</strong></a><code>(x, 50, interpolation='midpoint')</code>。</p>