function module¶
Utility functions¶
Functions complex_to_seq()
and seq_to_complex()
are useful to convert between the matrix representation of
complex numbers and Python complex
.
The function mean()
evaluates the mean of a sequence.
Module contents¶
-
complex_to_seq
(z)¶ Transform a complex number into a 4-element sequence
Parameters: z – a number If
z = x + yj
, then an array of the form[[x,-y],[y,x]]
can be used to representz
in matrix computations.- Examples::
>>> import numpy >>> z = 1 + 2j >>> function.complex_to_seq(z) (1.0, -2.0, 2.0, 1.0)
>>> m = numpy.array( function.complex_to_seq(z) ) >>> m.shape = (2,2) >>> print( m ) [[ 1. -2.] [ 2. 1.]]
-
seq_to_complex
(seq)¶ Transform a 4-element sequence into a complex number
Parameters: seq – a 4-element sequence Raises: RuntimeError – if seq
is ill-conditionedExamples:
>>> import numpy >>> seq = (1,-2,2,1) >>> z = function.seq_to_complex( seq ) >>> z (1+2j) >>> a = numpy.array((1,-2,2,1)) >>> a.shape = 2,2 >>> a array([[ 1, -2], [ 2, 1]]) >>> z = function.seq_to_complex(a) >>> z (1+2j)
-
mean
(seq, *args, **kwargs)¶ Return the arithmetic mean of the elements in seq
Parameters: If the elements of
seq
are uncertain numbers, an uncertain number is returned.Example
>>> seq = [ ureal(1,1), ureal(2,1), ureal(3,1) ] >>> function.mean(seq) ureal(2.0,0.5773502691896257,inf)