Complex¶
-
class
Complex(re=None, im=None)[source]¶ Bases:
objectThe Complex class implements a complex number.
This version adapted from the c++ and java implementations, originall authored by Allen Farris.
Methods Summary
compareTo(other)Compare this Complex to the specified other complex number, which must be a Complex, returning -1, 0, or +1 if the magnitude of this complex number is less than, equal to, or greater than the magnitude of the specified other complex number.
conj()Replace this complex number by it’s complex conjugate.
conjugate(a)Return a new complex number that is the complex conjugate of the specified complex number.
divide(a, b)Return a new complex number that is “a / b”.
equals(otherComplex)Return True if and only if the specified other complex number is a Complex and its value is equal to this complex number.
from1DBin(eis)Read a list of binary Complex values from an EndianInput instance and return the resulting list.
from2DBin(eis)Read a 2D list of binary Complex values from an EndianInput instance and return the resulting list.
from3DBin(eis)Read a 2D list of binary Complex values from an EndianInput instance and return the resulting list.
fromBin(eis)Read the binary representation of a Complex value from an EndianInput instance and use the read value to set a Complex value.
getImg()Return the imaginary part of this complex number.
getInstance(stringList)Retrieve two values from a list of strings and convert that to a Complex.
getReal()Return the real part of this complex number.
isZero()Return True if and only if this Complex number is zero.
ivalues(items)return a list of floats equal to the imaginary parts of the list of Complex objects passed in the items argument.
listTo1DBin(complexList, eos)Write a 1D list of Complex to the EndianOutput
listTo2DBin(complexList, eos)Write a 2D list of Complex to the EndianOutput
listTo3DBin(complexList, eos)Write a 3D list of Complex to the EndianOutput
listToBin(complexList, eos)Write a list of Complex to the EndianOutput.
multiply(a, b)Return a new complex number that is the product of the two specified complex numbers, a * b param a The first complex number of the pair.
rvalues(items)return a list of floats equal to the real parts of the list of Complex objects passed in the items argument.
setImg(im)Set the imaginary value of this complex number.
setReal(re)Set the real value of this complex number.
subtract(a, b)Return a new complex number that is the difference of the two specified complex numbers, a - b.
sum(a, b)Return a new complex number that is the sum of the two specified complex numbers, a + b.
toBin(eos)Write the binary representation of this into an EndianOutput
Methods Documentation
-
compareTo(other)[source]¶ Compare this Complex to the specified other complex number, which must be a Complex, returning -1, 0, or +1 if the magnitude of this complex number is less than, equal to, or greater than the magnitude of the specified other complex number.
-
static
conjugate(a)[source]¶ Return a new complex number that is the complex conjugate of the specified complex number. param a The complex number used to form its conjugate. return A new complex number that is the complex conjugate of a.
-
static
divide(a, b)[source]¶ Return a new complex number that is “a / b”. param a The first complex number of the pair. param b The second complex number of the pair. return a new Complex number that is “a / b”.
-
equals(otherComplex)[source]¶ Return True if and only if the specified other complex number is a Complex and its value is equal to this complex number. param otherComplex The other complex number to which this is being compared. return True if and only if the specified other complex number is a Complex and its value is equal to this complex number
-
static
from1DBin(eis)[source]¶ Read a list of binary Complex values from an EndianInput instance and return the resulting list.
-
static
from2DBin(eis)[source]¶ Read a 2D list of binary Complex values from an EndianInput instance and return the resulting list.
-
static
from3DBin(eis)[source]¶ Read a 2D list of binary Complex values from an EndianInput instance and return the resulting list.
-
static
fromBin(eis)[source]¶ Read the binary representation of a Complex value from an EndianInput instance and use the read value to set a Complex value.
return a Complex
-
static
getInstance(stringList)[source]¶ Retrieve two values from a list of strings and convert that to a Complex.
This is used when parsing Complex lists from an XML representation to eventually construct a list of Complex instances. The values are expected to be floats representing the real and imaginary parts of a complex number.
Returns a tuple of (Complex, stringList) where Complex is the new Complex created by this call and stringList is the remaining, unused, part of stringList after removing the first two elements.
-
static
ivalues(items)[source]¶ return a list of floats equal to the imaginary parts of the list of Complex objects passed in the items argument. items may also be a list of lists(2D array) of Complex objects. If the first item is a list then this method assumes that items is a list of lists and the return value is a list of lists of floats. The list of lists case is done by calling this method recursively and so it should work for higher orders of lists of lists. That use case is not tested.
-
static
listToBin(complexList, eos)[source]¶ Write a list of Complex to the EndianOutput. The list may have 1, 2 or 3 dimensions.
-
static
multiply(a, b)[source]¶ Return a new complex number that is the product of the two specified complex numbers, a * b param a The first complex number of the pair. param b The second complex number of the pair. return A new Complex number that is the product of the two specified complex numbers, a * b
-
static
rvalues(items)[source]¶ return a list of floats equal to the real parts of the list of Complex objects passed in the items argument. items may also be a list of lists(2D array) of Complex objects. If the first item is a list then this method assumes that items is a list of lists and the return value is a list of lists of floats. The list of lists case is done by calling this method recursively and so it should work for higher orders of lists of lists. That use case is not tested.
-
setImg(im)[source]¶ Set the imaginary value of this complex number. The float operator is used to ensure that im is used as a float by this class.
-
setReal(re)[source]¶ Set the real value of this complex number. The float operator is used to ensure that re is used as a float by this class.
-
static
subtract(a, b)[source]¶ Return a new complex number that is the difference of the two specified complex numbers, a - b. param a The first complex of the pair. param b The second complex of the pair. return A new Complex number that is the difference of the specified complex numbers, a - b.
-