Instantiates an all-ones variable and returns it. Arguments: shape: Tuple of integers, shape of returned Keras variable. dtype: String, data type of returned Keras variable. name: String, name of returned Keras variable. Returns: A Keras variable, filled with `1.0`.
(shape, dtype=None, name=None)
| 1307 | |
| 1308 | @keras_export('keras.backend.ones') |
| 1309 | def ones(shape, dtype=None, name=None): |
| 1310 | """Instantiates an all-ones variable and returns it. |
| 1311 | |
| 1312 | Arguments: |
| 1313 | shape: Tuple of integers, shape of returned Keras variable. |
| 1314 | dtype: String, data type of returned Keras variable. |
| 1315 | name: String, name of returned Keras variable. |
| 1316 | |
| 1317 | Returns: |
| 1318 | A Keras variable, filled with `1.0`. |
| 1319 | Note that if `shape` was symbolic, we cannot return a variable, |
| 1320 | and will return a dynamically-shaped tensor instead. |
| 1321 | |
| 1322 | Example: |
| 1323 | ```python |
| 1324 | >>> from keras import backend as K |
| 1325 | >>> kvar = K.ones((3,4)) |
| 1326 | >>> K.eval(kvar) |
| 1327 | array([[ 1., 1., 1., 1.], |
| 1328 | [ 1., 1., 1., 1.], |
| 1329 | [ 1., 1., 1., 1.]], dtype=float32) |
| 1330 | ``` |
| 1331 | """ |
| 1332 | with ops.init_scope(): |
| 1333 | if dtype is None: |
| 1334 | dtype = floatx() |
| 1335 | tf_dtype = dtypes_module.as_dtype(dtype) |
| 1336 | v = array_ops.ones(shape=shape, dtype=tf_dtype, name=name) |
| 1337 | if py_all(v.shape.as_list()): |
| 1338 | return variable(v, dtype=dtype, name=name) |
| 1339 | track_variable(v) |
| 1340 | return v |
| 1341 | |
| 1342 | |
| 1343 | @keras_export('keras.backend.eye') |
nothing calls this directly
no test coverage detected