Skip to content

Commit

Permalink
Improve docstring of Keras normalize utility.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 363924762
  • Loading branch information
fchollet authored and tensorflower-gardener committed Mar 19, 2021
1 parent 7adb536 commit e95dc8e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions keras/utils/np_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,24 @@ def to_categorical(y, num_classes=None, dtype='float32'):

@keras_export('keras.utils.normalize')
def normalize(x, axis=-1, order=2):
"""Normalizes a Numpy array.
"""Normalizes a NumPy array.
Args:
x: Numpy array to normalize.
axis: axis along which to normalize.
order: Normalization order (e.g. `order=2` for L2 norm).
x: NumPy array to normalize.
axis: Axis along which to normalize. For instance, `axis=-1` corresponds
to feature-wise normalization.
order: Normalization order (e.g. `order=2` for the L2 norm).
Returns:
A normalized copy of the array.
Example:
>>> array = np.random.random(size=(32, 3))
>>> normalized_array = tf.keras.utils.normalize(array, axis=-1)
>>> # Every element in the batch has now a unit norm
>>> for i in range(32):
>>> np.testing.assert_allclose(np.square(normalized_array[i, :]).sum(), 1)
"""
l2 = np.atleast_1d(np.linalg.norm(x, order, axis))
l2[l2 == 0] = 1
Expand Down

0 comments on commit e95dc8e

Please sign in to comment.