tf.constant

Creates a constant tensor from a tensor-like object.

Used in the notebooks

Used in the guide Used in the tutorials

If the argument dtype is not specified, then the type is inferred from the type of value.

# Constant 1-D Tensor from a python list.
tf.constant([1, 2, 3, 4, 5, 6])
<tf.Tensor: shape=(6,), dtype=int32,
    numpy=array([1, 2, 3, 4, 5, 6], dtype=int32)>
# Or a numpy array
a = np.array([[1, 2, 3], [4, 5, 6]])
tf.constant(a)
<tf.Tensor: shape=(2, 3), dtype=int64, numpy=