MCPcopy Create free account
hub / github.com/numpy/numpy / norm

Function norm

numpy/linalg/linalg.py:2384–2633  ·  view source on GitHub ↗

Matrix or vector norm. This function is able to return one of eight different matrix norms, or one of an infinite number of vector norms (described below), depending on the value of the ``ord`` parameter. Parameters ---------- x : array_like Input array. If `a

(x, ord=None, axis=None, keepdims=False)

Source from the content-addressed store, hash-verified

2382
2383@array_function_dispatch(_norm_dispatcher)
2384def norm(x, ord=None, axis=None, keepdims=False):
2385 """
2386 Matrix or vector norm.
2387
2388 This function is able to return one of eight different matrix norms,
2389 or one of an infinite number of vector norms (described below), depending
2390 on the value of the ``ord`` parameter.
2391
2392 Parameters
2393 ----------
2394 x : array_like
2395 Input array. If `axis` is None, `x` must be 1-D or 2-D, unless `ord`
2396 is None. If both `axis` and `ord` are None, the 2-norm of
2397 ``x.ravel`` will be returned.
2398 ord : {non-zero int, inf, -inf, 'fro', 'nuc'}, optional
2399 Order of the norm (see table under ``Notes``). inf means numpy's
2400 `inf` object. The default is None.
2401 axis : {None, int, 2-tuple of ints}, optional.
2402 If `axis` is an integer, it specifies the axis of `x` along which to
2403 compute the vector norms. If `axis` is a 2-tuple, it specifies the
2404 axes that hold 2-D matrices, and the matrix norms of these matrices
2405 are computed. If `axis` is None then either a vector norm (when `x`
2406 is 1-D) or a matrix norm (when `x` is 2-D) is returned. The default
2407 is None.
2408
2409 .. versionadded:: 1.8.0
2410
2411 keepdims : bool, optional
2412 If this is set to True, the axes which are normed over are left in the
2413 result as dimensions with size one. With this option the result will
2414 broadcast correctly against the original `x`.
2415
2416 .. versionadded:: 1.10.0
2417
2418 Returns
2419 -------
2420 n : float or ndarray
2421 Norm of the matrix or vector(s).
2422
2423 See Also
2424 --------
2425 scipy.linalg.norm : Similar function in SciPy.
2426
2427 Notes
2428 -----
2429 For values of ``ord < 1``, the result is, strictly speaking, not a
2430 mathematical 'norm', but it may still be useful for various numerical
2431 purposes.
2432
2433 The following norms can be calculated:
2434
2435 ===== ============================ ==========================
2436 ord norm for matrices norm for vectors
2437 ===== ============================ ==========================
2438 None Frobenius norm 2-norm
2439 'fro' Frobenius norm --
2440 'nuc' nuclear norm --
2441 inf max(sum(abs(x), axis=1)) max(abs(x))

Callers 14

test_emptyMethod · 0.90
_testMethod · 0.90
test_axisMethod · 0.90
test_keepdimsMethod · 0.90
test_matrix_emptyMethod · 0.90
test_matrix_2x2Method · 0.90
test_matrix_3x3Method · 0.90
test_longdouble_normMethod · 0.90
test_intminMethod · 0.90
testNormMethod · 0.85

Calls 14

asarrayFunction · 0.90
normalize_axis_indexFunction · 0.90
isComplexTypeFunction · 0.85
absFunction · 0.85
_multi_svd_normFunction · 0.85
astypeMethod · 0.80
dotMethod · 0.80
reshapeMethod · 0.80
sqrtFunction · 0.50
ravelMethod · 0.45
maxMethod · 0.45
minMethod · 0.45

Tested by 13

test_emptyMethod · 0.72
_testMethod · 0.72
test_axisMethod · 0.72
test_keepdimsMethod · 0.72
test_matrix_emptyMethod · 0.72
test_matrix_2x2Method · 0.72
test_matrix_3x3Method · 0.72
test_longdouble_normMethod · 0.72
test_intminMethod · 0.72
testNormMethod · 0.68