abs
Syntax
abs(X)
Parameters
X is a scalar/pair/vector/matrix/dictionary/table.
Details
Return the element-by-element absolute value(s) of X.
The abs function in DolphinDB has the same functionality as the
abs functions in Python, NumPy, and
scipy.stats
, with the following difference: Python/NumPy/scipy.stats
support calculating the absolute value of complex numbers,whereas DolphinDB’s
abs function does not support complex numbers. To calculate
the absolute value of complex numbers in DolphinDB, you can use the
abs function provided in the DolphinDB signal plugin
(see example).
Examples
abs(-2.0);
// output: 2
abs(-2 -3 4);
// output: [2, 3, 4]
Calculate the absolute value of a complex number using the signal
plugin.
// Check whether the signal plugin exists in the plugin marketplace
listRemotePlugins()
// Download the signal plugin from the marketplace
installPlugin("signal")
// Load the signal plugin
loadPlugin("signal")
// Create a complex number
z = complex(3, 4) // 3.0+4.0i
// Calculate the absolute value of the complex number
abs = signal::abs(z)
abs
// output: 5