mlx.nn.init.constant#

constant(value: float, dtype: Dtype = mlx.core.float32) Callable[[array], array]#

An initializer that returns an array filled with value.

Parameters:
  • value (float) – The value to fill the array with.

  • dtype (Dtype, optional) – The data type of the array. Default: float32.

Returns:

An initializer that returns an array with the same shape as the input, filled with value.

Return type:

Callable[[array], array]

Example

>>> init_fn = nn.init.constant(0.5)
>>> init_fn(mx.zeros((2, 2)))
array([[0.5, 0.5],
       [0.5, 0.5]], dtype=float32)