Questions tagged [subtraction]

Subtraction is a mathematical operation that represents the removal of an object from a collection.

Subtraction is a mathematical operation that represents the removal of an object from a collection. The minus sign (-) signifies subtraction.

Subtraction is anticommutative, meaning that changing the order changes the sign of the answer. It is not associative, meaning that when one subtracts more than two numbers, order in which subtraction is performed matters.

Basic Subtraction

You can imagine a number line that begins at position 3. If you subtract 2 from the starting position of 3, you will be left with 1.

3 - 2 = 1

3-2 number line

Source

1476 questions
200
votes
11 answers

How to subtract X days from a date using Java calendar?

Anyone know a simple way using Java calendar to subtract X days from a date? I have not been able to find any function which allows me to directly subtract X days from a date in Java. Can someone point me to the right direction?
fmsf
  • 36,317
  • 49
  • 147
  • 195
122
votes
11 answers

Add/Subtract months/years to date in dart?

I saw that in dart there is a class Duration but it cant be used add/subtract years or month. How did you managed this issue, I need to subtract 6 months from an date. Is there something like moment.js for dart or something around? Thank you
cosinus
  • 1,905
  • 3
  • 15
  • 21
116
votes
3 answers

Set difference versus set subtraction

What distinguishes - and .difference() on sets? Obviously the syntax is not the same. One is a binary operator, and the other is an instance method. What else? s1 = set([1,2,3]) s2 = set([3,4,5]) >>> s1 - s2 set([1, 2]) >>>…
David542
  • 104,438
  • 178
  • 489
  • 842
68
votes
10 answers

How to remove a pandas dataframe from another dataframe

How to remove a pandas dataframe from another dataframe, just like the set subtraction: a=[1,2,3,4,5] b=[1,5] a-b=[2,3,4] And now we have two pandas dataframe, how to remove df2 from df1: In [5]:…
176coding
  • 2,933
  • 4
  • 17
  • 18
54
votes
11 answers

Subtract n hours from a DateTime in Ruby

I have a Ruby DateTime which gets filled from a form. Additionally I have n hours from the form as well. I'd like to subtract those n hours from the previous DateTime. (To get a time range). DateTime has two methods "-" and "<<" to subtract day and…
43
votes
11 answers

PHP subtract 1 month from date formatted with date ('m-Y')

I'm trying to subtract 1 month from a date. $today = date('m-Y'); This gives: 08-2016 How can I subtract a month to get 07-2016?
Grant
  • 433
  • 1
  • 4
  • 4
39
votes
4 answers

PHP: simplest way to get the date of the month 6 months prior on the first?

So if today was April 12, 2010 it should return October 1, 2009 Some possible solutions I've googled seem overly complex, any suggestions?
stormist
  • 5,709
  • 12
  • 46
  • 65
38
votes
10 answers

Why is subtraction faster than addition in Python?

I was optimising some Python code, and tried the following experiment: import time start = time.clock() x = 0 for i in range(10000000): x += 1 end = time.clock() print '+=',end-start start = time.clock() x = 0 for i in range(10000000): x…
Statto
  • 381
  • 3
  • 3
35
votes
11 answers

Subtraction between two sql queries

I have 2 queries in MS SQL that return a number of results using the COUNT function. I can run the the first query and get the first result and then run the other one to get the other result, subtract them and find the results; however is there a…
andreas
  • 351
  • 1
  • 3
  • 3
34
votes
6 answers

Removing elements from an array in C

I just have a simple question about arrays in C: What is the best way to remove elements from an array and in the process make the array smaller. ie: the array is n size, then I take elements out of the array and then the array grows smaller by the…
Rini Posny
  • 343
  • 1
  • 4
  • 5
33
votes
5 answers

Subtract objects in one NSArray from another array

I have two NSArrays: NSArray *wants = [NSArray arrayWithObjects: @"apples", @"oranges", @"pineapple", @"mango", @"strawberries", …
Jacksonkr
  • 31,583
  • 39
  • 180
  • 284
26
votes
5 answers

How to subtract two lists in python

I can't figure out how to make a function in python that can calculate this: List1=[3,5,6] List2=[3,7,2] and the result should be a new list that substracts List2 from List1, List3=[0,-2,4]! I know, that I somehow have to use the zip-function. By…
Linus Svendsson
  • 1,417
  • 6
  • 18
  • 21
26
votes
2 answers

How to subtract a vector from each row of a matrix?

Possible Duplicate: How can I divide each row of a matrix by a fixed row? I'm looking for an elegant way to subtract the same vector from each row of a matrix. Here is a non elegant way of doing it. a = [1 2 3]; b = rand(7,3); c(:,1) = b(:,1) -…
Miebster
  • 2,365
  • 4
  • 21
  • 27
26
votes
4 answers

How to subtract a month from Date object?

How do I subtract a month from a date object in VB.NET? I have tried: Today.AddMonths(-1) However, given that Today is 01-Jan-2010, the result I get is 01-Dec-2010. The answer I want is 01-Dec-2009. Is there a convenient way of doing this within…
Andrew
  • 11,068
  • 17
  • 52
  • 62
26
votes
8 answers

How to subtract two strings?

I have a long string, which is basically a list like str="lamp, bag, mirror," (and other items) I was wondering if I can add or subtract some items, in other programming languages I can easily do: str=str-"bag," and get str="lamp, mirror," this…
max smith
  • 273
  • 1
  • 3
  • 4
1
2 3
98 99