SciPy

numpy.absolute

numpy.absolute(x[, out]) = <ufunc 'absolute'>

Calculate the absolute value element-wise.

Parameters:

x : array_like

Input array.

Returns:

absolute : ndarray

An ndarray containing the absolute value of each element in x. For complex input, a + ib, the absolute value is

System Message: WARNING/2 (\sqrt{ a^2 + b^2 })

latex exited with error [stdout] This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015/TeX Live for SUSE Linux) (preloaded format=latex) restricted \write18 enabled. entering extended mode (./math.tex LaTeX2e <2015/01/01> patch level 2 Babel <3.9m> and hyphenation patterns for 79 languages loaded. (/usr/share/texmf/tex/latex/base/article.cls Document Class: article 2014/09/29 v1.4h Standard LaTeX document class (/usr/share/texmf/tex/latex/base/size12.clo)) (/usr/share/texmf/tex/latex/base/inputenc.sty ! LaTeX Error: File `utf8x.def’ not found. Type X to quit or <RETURN> to proceed, or enter new name. (Default extension: def) Enter file name: ! Emergency stop. <read *> l.173 \endinput ^^M No pages of output. Transcript written on math.log.

.

Examples

>>> x = np.array([-1.2, 1.2])
>>> np.absolute(x)
array([ 1.2,  1.2])
>>> np.absolute(1.2 + 1j)
1.5620499351813308

Plot the function over [-10, 10]:

>>> import matplotlib.pyplot as plt
>>> x = np.linspace(start=-10, stop=10, num=101)
>>> plt.plot(x, np.absolute(x))
>>> plt.show()

(Source code, png, pdf)

../../_images/numpy-absolute-1_00_00.png

Plot the function over the complex plane:

>>> xx = x + 1j * x[:, np.newaxis]
>>> plt.imshow(np.abs(xx), extent=[-10, 10, -10, 10])
>>> plt.show()

(png, pdf)

../../_images/numpy-absolute-1_01_00.png

Previous topic

numpy.square

Next topic

numpy.fabs