Questions tagged [absolute-value]

Absolute value is a mathematical function that returns the non-negative value of a number without regard to its sign.

Absolute value is a mathematical function that returns the non-negative value of a number without regard to its sign.

For example, both 7 and -7 will have an absolute value of 7.

Many programming languages include a function for absolute value in their standard math libraries, often named abs() or similar.

More information: http://en.wikipedia.org/wiki/Absolute_value

219 questions
8
votes
1 answer

Julia - absolute value of an array

I want to get the absolute value of the following array: x = [1.1 -22.3 3.01, -1] i.e.: I want an output of the type: x2 = [1.1 22.3 3.01 1] However when I type: abs(x) I get an error: ERROR: MethodError: no method matching…
ecjb
  • 5,169
  • 12
  • 43
  • 79
8
votes
2 answers

Why is numpy.absolute() so slow?

I need to optimize a script that makes heavy use of computing L1 norm of vectors. As we know L1 norm in this case is just a sum of absolute values. When timing how fast numpy is in this task I found something weird: addition of all vector elements…
Lugi
  • 573
  • 4
  • 20
8
votes
1 answer

Calculating absolute value in Python

How do I make a program that asks for one floating point number in Python and then calculates the absolute value? I've already tried the asking, but I can't make the line where it calculates the absolute value.
K.Kane
  • 115
  • 1
  • 1
  • 2
7
votes
7 answers

Unsigned int to signed in php

It appears, that in 32bit OS ip2long returns signed int, and in 64bit OS unsigned int is returned. My application is working on 10 servers, and some are 32bit and some are 64bit, so I need all them to work same way. In PHP documentation there is a…
Thinker
  • 14,234
  • 9
  • 40
  • 55
7
votes
2 answers

Interpreting the effect of LK Norm with different orders on training machine learning model with the presence of outliers

( Both the RMSE and the MAE are ways to measure the distance between two vectors: the vector of predictions and the vector of target values. Various distance measures, or norms, are possible. Generally speaking, calculating the size or length of a…
I. A
  • 2,252
  • 26
  • 65
7
votes
2 answers

Is there any difference between std::abs and std::fabs when applied to floating point values?

There is a related question but I believe it doesn't answer this question. Looking at std::abs and std::fabs documentation they seems to have exactly the same behaviour. As a personal note, it appears to me that std::fabs is preferable because it…
Antonio
  • 19,451
  • 13
  • 99
  • 197
7
votes
1 answer

How does this function compute the absolute value of a float through a NOT and AND operation?

I am trying to understand how the following code snippet works. This program uses SIMD vector instructions (Intel SSE) to calculate the absolute value of 4 floats (so, basically, a vectorized "fabs()" function). Here is the snippet: #include…
Mark Anderson
  • 2,399
  • 3
  • 15
  • 21
7
votes
1 answer

How/why do we use operator.abs

In operators module we have a helper method operator.abs. But in python abs is already a function, and the only way I know to invoke the __abs__ method on an object is by function call anyway. Is there some other fancy way I don't know about to…
wim
  • 338,267
  • 99
  • 616
  • 750
6
votes
1 answer

how to define colormap with absolute values with matplotlib

I use the following script for plotting: import matplotlib import matplotlib.pyplot as plt import numpy as np import pylab as pl import math import matplotlib as mpl from matplotlib.ticker import MultipleLocator from matplotlib.colors import…
DonkeyKong
  • 465
  • 1
  • 5
  • 16
5
votes
4 answers

How could I safely find the absolute difference between 2 signed integers in C?

An absolute difference would be the absolute value of the difference between 2 numbers. Suppose I have 2 int variables (x and y) and I would like to find the absolute difference. An easy solution would be: unsigned diff = abs(x-y); However these…
user16217248
  • 3,119
  • 19
  • 19
  • 37
5
votes
4 answers

The Absolute Value of a Complex Number with Numpy

I have the following script in Python. I am calculating the Fourier Transform of an array. When I want to plot the results (Fourier transform) I am using the absolute value of that calculation. However, I do not know how the absolute value of…
jAdex
  • 472
  • 1
  • 5
  • 15
5
votes
6 answers

How do I get the absolute value of an integer without using Math.abs?

How do I get the absolute value of a number without using math.abs? This is what I have so far: function absVal(integer) { var abs = integer * integer; return abs^2; }
chaneyz
  • 95
  • 1
  • 1
  • 6
5
votes
2 answers

Why is there a blas subroutine (ISAMAX) for argmax abs but none for argmax?

Why is there a blas subroutine ISAMAX for argmax abs but not for argmax ? In C++ using std::max_element with compiler optimisation flag -O3 I am getting speeds comparable to blas_isamax (16 ms vs 9 ms), so at the moment my question is more out of…
newling
  • 624
  • 6
  • 10
4
votes
2 answers

sympy: how to evaluate integral of absolute value

When I try to simplify the following integral in sympy, it will not evaluate, i.e. the output is $\int_{-1}^1 |z| dz$ while the output I expect is 1. z = symbols('z', real=True) a = integrate(abs(z), (z, -1, 1)) simplify(a) Similar integral without…
Brian
  • 3,453
  • 2
  • 27
  • 39
4
votes
2 answers

Matlab: if statements and abs() function in variable-step ODE solvers

I was reading this post online where the person mentioned that using "if statements" and "abs()" functions can have negative repercussions in MATLAB's variable-step ODE solvers (like ODE45). According to the OP, it can significantly affect time-step…
Kimusubi
  • 155
  • 1
  • 8
1 2
3
14 15