Tensorflow.js tf.norm() Function
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment.
The tf.norm() function is used compute the norm of matrices, vectors, and scalar. This function can also compute several other vector norms such as the 1-norm, the 2-norm or Euclidean, the inf-norm, and in general the p-norm for p > 0 and matrix norms.
tf.norm (x, ord?, axis?, keepDims?)
Parameters: This function accepts four parameters which is illustrated below:
- x: The specifies the input array.
- ord: This is optional. It specifies the order of the norm.
- axis: This is optional. If axis is null, then the input is considered as a vector and a single vector norm is calculated over the whole set of values in the Tensor, i.e. norm(x, ord) is equivalent to norm(x.reshape([-1]), ord). Whereas if axis is an integer, then the input is inspected as a batch of vectors, and axis determines the x-axis over which vector norms is computed. If axis is a 2-tuple of integer it is considered as a batch of matrices and axis determines the axes in N-d array over which to compute a matrix norm.
- keepDims: This is optional. If it is set to true, then the norm have the same dimension as the input.
Return Value: It returns tf.tensor.
Below are the examples that illustrates the use of tf.norm() function.