Skip to content

Commit

Permalink
add functin to subtract qnArrayTwo objects
Browse files Browse the repository at this point in the history
  • Loading branch information
mayya-bondarevskaya committed Jul 4, 2017
1 parent 33868f3 commit 30f8afc
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pyqn/qn_array_two.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,23 @@ def __add__(self, other):
temp_q = Quantity(value=self[i], units=self.units) + other
v.append(temp_q.value)
return qnArrayTwo(v, units = temp_q.units)
else:
raise qnArrayTwoError("Can only add two qnArray objects or a qnArray with Quantity")

def __sub__(self, other):
if type(other) is qnArrayTwo:
if len(other) != len(self):
raise qnArrayTwoError("Inconsistent array lengths")
v = []
for i in range(len(self)):
temp_q = Quantity(value = self[i], units = self.units) - Quantity(value = other[i], units = other.units)
v.append(temp_q.value)
return qnArrayTwo(v, units = temp_q.units)
if type(other) is Quantity:
v = []
for i in range(len(self)):
temp_q = Quantity(value=self[i], units=self.units) - other
v.append(temp_q.value)
return qnArrayTwo(v, units = temp_q.units)
else:
raise qnArrayTwoError("Can only add two qnArray objects or a qnArray with Quantity")

0 comments on commit 30f8afc

Please sign in to comment.