From: Kenny O. <kor...@id...> - 2006-10-03 17:03:17
|
Yeah thanks guys, I printed them out the size and realized what it was doing then used a for loop to put it into the 1D array, but thanks Travis the way you said makes it easier than the for loop. -Kenny |
From: Kenny O. <kor...@id...> - 2006-10-03 20:02:33
|
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 |
From: David L G. <Dav...@no...> - 2006-10-03 20:33:26
|
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. 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 > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > -- HMRD/ORR/NOS/NOAA <http://response.restoration.noaa.gov/emergencyresponse/> |
From: Tim H. <tim...@ie...> - 2006-10-03 20:38:25
|
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 >> Num...@li... >> https://lists.sourceforge.net/lists/listinfo/numpy-discussion >> >> > > > |
From: Tim H. <tim...@ie...> - 2006-10-03 20:35:07
|
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? There may be a better way, but:: alltrue(isreal(x)) Would work. As would: not sometrue(x.imag) In the above test you are already negating the test, so you could just drop the not. > 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? > I'm not entirely sure what you are looking for here, but x.imag and x.real will give you the real and imaginary parts. abs(x) will return the magnitude of x whether x is real or complex. x.conj() will return complex conjugate. I'm somewhat suspicious of that matlab code. The code given is discontinuous as you cross the negative real axis. Does the result subsequently get squared or something? I'm guessing that either the matlab code is doing extra work, or there are some hidden assumptions (all values are in the positive real half-plane). Or some such. In either case, you'd probably be OK just skipping the check for realness and always taking the absolute of array. I can't say for sure without more context though. -tim |
From: David G. <Dav...@no...> - 2006-10-03 20:22:04
|
numpy.isreal(a) is a "top level" function (i.e., not a class member function) in numpy; here's its help doc: Help on function isreal in module numpy.lib.type_check: isreal(x) Return a boolean array where elements are True if that element is real (has zero imaginary part) For scalars, return a boolean. As for checking for pure imaginaries (i.e., real part == 0), one could use: x.imag == -j*x or numpy.isreal(i*x) or simply (x.real == 0.0) and (x.imag != 0.0) 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 > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > |
From: David L G. <Dav...@no...> - 2006-10-03 21:22:06
|
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 >>> Num...@li... >>> 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 > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > -- HMRD/ORR/NOS/NOAA <http://response.restoration.noaa.gov/emergencyresponse/> |