Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why subtract a value from itself (x - x) in Python?

In NumPy functions, there are often initial lines that do checking of variable types, forcing them to be certain types, etc. Can someone explain the point of these lines in scipy.signal.square? What does subtracting a value from itself do?

t,w = asarray(t), asarray(duty)
w = asarray(w + (t-t))
t = asarray(t + (w-w))

source

like image 333
endolith Avatar asked May 20 '10 15:05

endolith


People also ask

How do you subtract a value from a variable in Python?

Python provides the operator x -= y to subtract two objects in-place by calculating the difference x - y and assigning the result to the first operands variable name x .

How do you subtract a number from each element in a list Python?

How do you subtract a number from each element in a list Python? for i in range(len(numbers)): numbers[i] = numbers[i] - 1.

Can we subtract 2 lists in Python?

Method 3: Use a list comprehension and set to Find the Difference Between Two Lists in Python. In this method, we convert the lists into sets explicitly and then simply reduce one from the other using the subtract operator.


1 Answers

I believe that this will make the final w and t have the same type. For example, if you start with float and int, you will end up with both being float arrays which is better for subsequent operations.

like image 104
Meh Avatar answered Sep 29 '22 23:09

Meh