November 2018
Intermediate to advanced
322 pages
7h 54m
English
Tensors can be created from Python objects such as lists, NumPy arrays, and pandas DataFrames. To create tensors from Python objects, use the tf.convert_to_tensor() function with the following definition:
tf.convert_to_tensor( value, dtype=None, name=None, preferred_dtype=None )
Let's practice doing this by creating some tensors and printing their definitions and values:
tf_t=tf.convert_to_tensor(5.0,dtype=tf.float64)print('tf_t : ',tf_t)print('run(tf_t) : ',tfs.run(tf_t))
The output is as follows:
tf_t : Tensor("Const_1:0", shape=(), dtype=float64)run(tf_t) : 5.0
a1dim = np.array([1,2,3,4,5.99])print("a1dim Shape : ",a1dim.shape)tf_t=tf.convert_to_tensor(a1dim,dtype=tf.float64) ...Read now
Unlock full access