MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / zeros

Function zeros

tensorflow/python/keras/backend.py:1269–1305  ·  view source on GitHub ↗

Instantiates an all-zeros variable and returns it. Arguments: shape: Tuple or list of integers, shape of returned Keras variable dtype: data type of returned Keras variable name: name of returned Keras variable Returns: A variable (including Keras metadata), filled with

(shape, dtype=None, name=None)

Source from the content-addressed store, hash-verified

1267
1268@keras_export('keras.backend.zeros')
1269def zeros(shape, dtype=None, name=None):
1270 """Instantiates an all-zeros variable and returns it.
1271
1272 Arguments:
1273 shape: Tuple or list of integers, shape of returned Keras variable
1274 dtype: data type of returned Keras variable
1275 name: name of returned Keras variable
1276
1277 Returns:
1278 A variable (including Keras metadata), filled with `0.0`.
1279 Note that if `shape` was symbolic, we cannot return a variable,
1280 and will return a dynamically-shaped tensor instead.
1281
1282 Example:
1283
1284 ```python
1285 from tensorflow.keras import backend as K
1286 kvar = K.zeros((3,4))
1287 K.eval(kvar)
1288 # array([[ 0., 0., 0., 0.], [ 0., 0., 0., 0.],
1289 # [ 0., 0., 0., 0.]], dtype=float32)
1290 A = tf.constant([1,2,3])
1291 kvar2 = K.zeros(A.shape) # [0., 0., 0.] float32 by default
1292 kvar3 = K.zeros(A.shape,dtype=tf.int32) # [0, 0, 0] with int32 dtype
1293 kvar4 = K.zeros([2,3]) # [[0., 0., 0.], [0., 0., 0.]]
1294 ```
1295
1296 """
1297 with ops.init_scope():
1298 if dtype is None:
1299 dtype = floatx()
1300 tf_dtype = dtypes_module.as_dtype(dtype)
1301 v = array_ops.zeros(shape=shape, dtype=tf_dtype, name=name)
1302 if py_all(v.shape.as_list()):
1303 return variable(v, dtype=dtype, name=name)
1304 track_variable(v)
1305 return v
1306
1307
1308@keras_export('keras.backend.ones')

Callers

nothing calls this directly

Calls 4

floatxFunction · 0.85
track_variableFunction · 0.85
variableFunction · 0.70
as_listMethod · 0.45

Tested by

no test coverage detected