Creates a tensor with all elements set to 1.
Aliases:
tf.compat.v1.ones
tf.compat.v2.ones
tf.ones(
shape,
dtype=tf.dtypes.float32,
name=None
)
Used in the guide:
M
ig
ra
te
y
ou
rT
e
ns
or
Fl
ow
1
c
od
et
o
T
en
so
rF
lo
w2``
W
ri
ti
ng
c
us
to
ml
a
ye
rs
a
nd
m
od
el
sw
i
th
K
er
as
Used in the tutorials:
A
ut
om
at
ic
d
if
fe
re
nt
ia
ti
on
a
nd
g
ra
di
en
tt
a
pe
B
et
te
rp
e
rf
or
ma
nc
ew
i
th
t
f.
fu
nc
ti
on
T
ra
ns
fo
rm
er
m
od
el
f
or
l
an
gu
ag
eu
n
de
rs
ta
nd
in
g`` This operation returns a tensor of typedtype
withshape
shape
and all elements set to 1.
For example:
tf.ones([2, 3], tf.int32) # [[1, 1, 1], [1, 1, 1]]
Args:
shape
: A list of integers, a tuple of integers, or a 1-DTensor
of typeint32
.dtype
: The type of an element in the resultingTensor
.name
: Aname
for the operation (optional).
Returns:
A Tensor
with all elements set to 1.