``````

In [10]:

import tensorflow as tf
#import numpy as np
array1 =[1.5,1.7,2.4,3.4,4.55,6.35]
array2 =[1.9,1.95,1.988,2.49,3.38,4.65]
#print(np.mean(array))
#array1 = np.array([1.53, 2.53, 6.29, 7.88, 8.6], dtype=np.float32)
print ("array1 = ",array1)
#array2 = np.array([2.36, 5.25, 13.24, 16.88, 18.56], dtype=np.float32)
print ("array2 = ",array2)

``````
``````

array1 =  [1.5, 1.7, 2.4, 3.4, 4.55, 6.35]
array2 =  [1.9, 1.95, 1.988, 2.49, 3.38, 4.65]

``````
``````

In [12]:

size1=len(array1)
mean1 = sum(array1)/size1
print ("mean1 =" ,mean1)

size2=len(array2)
mean2 = sum(array2)/size2
print ("mean2 =" ,mean2)

``````
``````

mean1 = 3.3166666666666664
mean2 = 2.726333333333333

``````
``````

In [13]:

variance1 = 0
for x in range(0, size1):
variance1 =  variance1 + (pow((array1[x]-mean1),2)/size1)
print("variance1 =",variance1)

``````
``````

variance1 = 8.741666666666667

``````
``````

In [23]:

covar = 0
for x in range(0, size1):
covar = covar + (tf.multiply(tf.subtract(array1[x],mean1), tf.subtract(array2[x],mean2))/size1)

m = covar / variance1
c = mean2 - m *mean1
with tf.Session() as sess:
print("covariance = ",sess.run(covar))
print("m = ",sess.run(m))
print("c = ",sess.run(c))
print("Calculating the value of Y for array1 using y = mx+c")
array3 = []
# print(array3)
for x in range(0, size1):
# x= 2.53
y= m*array1[x]+c
array3.append(y)
print(sess.run(array3))

import matplotlib.pyplot as plt
plt.plot(array1, array2, 'ro')

#plt.plot(array1, array3, 'ro')
plt.show()

``````
``````

covariance =  1.67578
m =  0.1917
c =  2.09053
Calculating the value of Y for array1 using y = mx+c
[2.3780785, 2.4164186, 2.5506086, 2.7423086, 2.9627635, 3.3078237]

``````