How to Caculate Pearson Value in TensorFlow

Here is an example:

import tensorflow as tf
import numpy as np

x = np.array([[[3],[2],[2]],[[5],[5],[1]]],dtype=np.float32)
y = np.array([[[4],[3],[2]],[[1],[3],[1]]],dtype=np.float32)

xx = tf.convert_to_tensor(x,dtype=tf.float32)
yy = tf.convert_to_tensor(y,dtype=tf.float32)

xx_mean = tf.reduce_mean(xx,1, True); #
'''
[[[2.3333333]]

 [[3.6666667]]]
'''
xxx = xx - xx_mean
'''
[[[ 0.66666675]
  [-0.33333325]
  [-0.33333325]]

 [[ 1.3333333 ]
  [ 1.3333333 ]
  [-2.6666667 ]]]
'''

xxx1 = tf.square(xxx)
''''
[[[0.44444454]
  [0.11111106]
  [0.11111106]]

 [[1.7777776 ]
  [1.7777776 ]
  [7.1111116 ]]]
'''
xm = tf.reduce_sum(xxx1,axis=1)
'''
[[ 0.6666666]
 [10.666667 ]]
'''

yy_mean = tf.reduce_mean(yy,1, True);
yyy = yy - yy_mean
yyy1 = tf.square(yyy)
ym = tf.reduce_sum(yyy1,axis=1)


p2 = tf.sqrt(xm * ym)

m = tf.multiply(xxx, yyy)

p1 = tf.reduce_sum(m, axis=1)

p = p1/(p2+0.001)
pp = tf.reduce_mean(p)

z, pr = tf.contrib.metrics.streaming_pearson_correlation(xx, yy)

init = tf.global_variables_initializer() 
init_local = tf.local_variables_initializer()

with tf.Session() as sess:
    sess.run([init, init_local])
    print(sess.run(pr))
    print(sess.run(p))
    print(sess.run(pp))

The result is:

0.09869276
[[0.86527604]
 [0.49990624]]
0.68259114