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
2
votes
2 answers

mean of absolute value of groupby object pandas

I want to compute the mean of the absolute value of a grouped object. I.e. grouped = df.groupby([pd.TimeGrouper(3MS)]) dct['x'] = grouped['profit'].agg('mean') / grouped['cost'].abs().agg('mean') However, the above code results in an error. I…
codingknob
  • 11,108
  • 25
  • 89
  • 126
2
votes
2 answers

Averaging the absolute values of data in excel, ignoring blank (" ") cells

I am building a forecast method comparison tool in excel. I have to use excel for this particular task. I need to compare different types of errors (MAE-mean absolute error, RMSE-root mean squared error, etc) to show which method does the best…
henrythedj
  • 78
  • 1
  • 2
  • 12
2
votes
2 answers

How to calculate the true square root of a number with 3 user-defined functions

I need a bit of help and some tips on where to go For a programming assignment, I have to write a program that calculates the square root of the number that the user inputs and there are certain requirements. The main asks for the number and…
123890Sah
  • 17
  • 3
2
votes
2 answers

Finding absolute value with if statement

I have 2 int variables which the user needs to enter, and I need to find the absolute value of their difference, is there a way to do it on the same principle I have started in this code? Scanner scn = new Scanner(System.in); int yourfloor,…
Evy
  • 43
  • 7
2
votes
1 answer

simd code to check if two double values are sufficiently different

Suppose I have two double values, old and new. I would like to implement a vectorized function that returns old if abs(x-y) < p, and new otherwise. Here is the code (test.cpp): #include #include #define ARRAY_LENGTH 2 int…
Cattus
  • 147
  • 6
2
votes
1 answer

r two dataframe merge by absolute value of one column

I have two dataframes with same format looking like this: df1) name value score a 2 0.01 b 2 2.25 c 1 5.24 df2) name value score A 2 -8.01 B 2 -3.25 C 1 -2.24 I want to merge these two list according…
user2418838
  • 371
  • 3
  • 12
2
votes
2 answers

to sort the numbers usig absoluter value using stl c++

I am trying to sort the given array based on absolute value using stl sort function but it is not sorting in the specified order: The code that I wrote: int fun(int i,int j) { if(abs(i)
sac
  • 137
  • 2
  • 5
  • 15
2
votes
1 answer

Absolute Value constraints in lpSolve in R

I would like to further constrain the system below with the following additional constraint, which makes use of the absolute value operator: abs(x1)+abs(x2)+abs(x3) <= 10 Is there a feasible way to implement these additional absolute value…
jd8585
  • 187
  • 1
  • 8
2
votes
1 answer

Is there a more efficient way to calculate the absolute value of a subtraction expression

The question pretty much says it all. At the moment, I'm using Math.Abs(a - b) to calculate the absolute value of a subtraction expression, example 5 - 10 and 10 - 5 both returning 5. Is there a more efficient way to do this, or it is the most…
Shadow
  • 3,926
  • 5
  • 20
  • 41
2
votes
2 answers

User defined function for getting absolute value

Using Wing ide 3.3.5 How would I write a function my_abs(value) that returns the absolute value of its x, without using the built-in abs function in Python. For example: Test Result print(my_abs(3.5)) 3.5 print(my_abs(-7.0)) 7.0
2
votes
5 answers

how to get absolute value of a number in java using bit manipulation

I want to implement a function to get the absolute value of a number in java: do nothing if it is positive, if it is negative, convert to positive. I want to do this only using bit manipulations and no number comparators. Please help
Sid
  • 125
  • 2
  • 11
2
votes
2 answers

Intro to C: Declaration of Functions

I want to declare a function for use in my code in ANSI C. Am I allowed to define the function after using it in main()? For example an absolute value function that I wrote: can anyone tell me if it's sound? #include int main() { …
Andrew Hu
  • 113
  • 1
  • 8
2
votes
2 answers

Computing the absolute value of an n-bit 2's complement number

The method takes in an n-bit 2's complement number whose absolute value we're trying to find, and the number of bits that the number will be. Here are some examples: abs(0x00001234, 16); // => 0x00001234 abs(0x00001234, 13); // => 0x00000DCC So you…
Evan LaHurd
  • 977
  • 2
  • 14
  • 27
2
votes
2 answers

Sort a list of ints and floats with negative and positive values?

I'm trying to sort a list of unknown values, either ints or floats or both, in ascending order. i.e, [2,-1,1.0] would become [-1,1.0,2]. Unfortunately, the sorted() function doesn't seem to work as it seems to sort in descending order by absolute…
Logan Shire
  • 5,013
  • 4
  • 29
  • 37
1
vote
1 answer

Swap start_time with end_time (vice versa) in a table using R

I am dealing with a bike sharing data set and in its raw data, the start_time has been keyed in with the end_time and vice versa. start time is later than end time Is there a way I can swap the two columns for the affected rows or is there a way to…