In [3]:
import tensorflow as tf

x1 = tf.constant(1, dtype=tf.float32)
y1 = tf.constant(2, dtype=tf.float32)
point1 = tf.pack([x1, y1])

In [10]:
with tf.Session() as session:
    print(session.run(point1))
    print(session.run(tf.transpose([point1])))


[ 1.  2.]
[[ 1.]
 [ 2.]]

In [13]:
x2 = tf.constant(2, dtype=tf.float32)
y2 = tf.constant(3, dtype=tf.float32)
point2 = tf.pack([x2, y2])

with tf.Session() as session:
    print(session.run(point1))    
    print(session.run(point2))


[ 1.  2.]
[ 2.  3.]

In [14]:
points = tf.transpose(tf.pack([point1, point2]))

In [15]:
with tf.Session() as session:
    print(session.run(points))


[[ 1.  2.]
 [ 2.  3.]]

In [24]:
ones = tf.ones((1, 2))

params = tf.matmul(ones, tf.matrix_inverse(points))

with tf.Session() as session:
    result = session.run(params)
    print(result)

    
    print(session.run(ones))
    print(session.run(tf.matrix_inverse(points)))
    #print(session.run(tf.matrix_determinant(points)))


[[-1.  1.]]
[[ 1.  1.]]
[[-3.  2.]
 [ 2. -1.]]

In [34]:
# Canonical equation for the circle: x^2 + y^2 + dx + ey + f = 0
points = tf.constant([[2, 1],
                      [0, 5],
                      [-1, 2]], dtype=tf.float64)

A = tf.constant([
    [2, 1, 1],
    [0, 5, 1],
    [-1, 2, 1]
], dtype='float64')

B = -tf.constant([[5], [25], [5]])
X = tf.matrix_solve(A, B)
with tf.Session() as session:
    result = session.run(X)
    D, E, F = result.flatten()

    print(D, E, F)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/Users/cprakashagr/Virtualenv/Tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py in apply_op(self, op_type_name, name, **keywords)
    453                 values, name=input_arg.name, dtype=dtype,
--> 454                 as_ref=input_arg.is_ref)
    455           except ValueError:

/Users/cprakashagr/Virtualenv/Tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py in convert_to_tensor(value, dtype, name, as_ref)
    627       if isinstance(value, base_type):
--> 628         ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
    629         if ret is NotImplemented:

/Users/cprakashagr/Virtualenv/Tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py in _TensorTensorConversionFunction(t, dtype, name, as_ref)
    570         "Tensor conversion requested dtype %s for Tensor with dtype %s: %r"
--> 571         % (dtype.name, t.dtype.name, str(t)))
    572   return t

ValueError: Tensor conversion requested dtype float64 for Tensor with dtype int32: 'Tensor("Neg_6:0", shape=(3, 1), dtype=int32)'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-34-eb2e3fc1bcfe> in <module>()
     11 
     12 B = -tf.constant([[5], [25], [5]])
---> 13 X = tf.matrix_solve(A, B)
     14 with tf.Session() as session:
     15     result = session.run(X)

/Users/cprakashagr/Virtualenv/Tensorflow/lib/python3.5/site-packages/tensorflow/python/ops/gen_linalg_ops.py in matrix_solve(matrix, rhs, adjoint, name)
    491   """
    492   result = _op_def_lib.apply_op("MatrixSolve", matrix=matrix, rhs=rhs,
--> 493                                 adjoint=adjoint, name=name)
    494   return result
    495 

/Users/cprakashagr/Virtualenv/Tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py in apply_op(self, op_type_name, name, **keywords)
    466                   "%s type %s of argument '%s'." %
    467                   (prefix, dtypes.as_dtype(attrs[input_arg.type_attr]).name,
--> 468                    inferred_from[input_arg.type_attr]))
    469 
    470           types = [values.dtype]

TypeError: Input 'rhs' of 'MatrixSolve' Op has type int32 that does not match type float64 of argument 'matrix'.

In [31]:
B = -tf.constant([[5], [25], [5]])
with tf.Session() as session:
    print(session.run(B))


[[ -5]
 [-25]
 [ -5]]

In [ ]: