[Numpy-discussion] complex numbers
David L Goldsmith
David.L.Goldsmith at noaa.gov
Tue Oct 3 17:21:55 EDT 2006
Thanks Tim,
DG
Tim Hochberg wrote:
> David L Goldsmith wrote:
>
>> PS: The Python built in function (i.e., you don't even need numpy for
>> this) abs(x) is "vectorized" (i.e., accepts a (nested) sequence, incl.
>> numpy array, argument) and overloaded to give the modulus (i.e.,
>> Pythagorean "length") of a complex number when such is its argument.
>>
>>
> This isn't quite right. The built in abs function looks for the special
> method __abs__. So, abs(x) is equivalent to x.__abs__(). Arrays supply
> an appropriate __abs__ method, lists do not. For example:
>
> >>> l = [1,2,3,4]
> >>> abs(l)
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: bad operand type for abs()
> >>> a = numpy.arange(5)
> >>> abs(a)
> array([0, 1, 2, 3, 4])
>
>
> -tim
>
>> DG
>>
>> Kenny Ortmann wrote:
>>
>>
>>> excuse my laziness for not looking this up, I googled it but could not find
>>> a solution.
>>> matlab has a
>>> isreal(array)
>>> where if the array is full of real numbers the value returned is 1.
>>> I'm translating matlab code and ran across
>>>
>>> if ~isreal(array)
>>> array = abs(array)
>>>
>>> Is there a way to check to see if a number is real or complex? and if so is
>>> there a way to extract the(a + ib) because the absolute value of a complex
>>> number is like the pythagorean therom on a and b?
>>>
>>> thanks for your help,
>>> Kenny
>>>
>>>
>>>
>>> -------------------------------------------------------------------------
>>> Take Surveys. Earn Cash. Influence the Future of IT
>>> Join SourceForge.net's Techsay panel and you'll get the chance to share your
>>> opinions on IT & business topics through brief surveys -- and earn cash
>>> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>>> _______________________________________________
>>> Numpy-discussion mailing list
>>> Numpy-discussion at lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>>>
>>>
>>>
>>
>>
>
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>
--
HMRD/ORR/NOS/NOAA <http://response.restoration.noaa.gov/emergencyresponse/>
More information about the NumPy-Discussion
mailing list