|
Re: Compare strings.array with None.: msg#00025python.numeric.general
On Mon, 2004-09-06 at 23:11, Shin wrote: > I got the following strange behavior in numarray.strings. > Is it intended or a bug? Thanks. > > >>> from numarray import * > >>> x = [1,2] > >>> x == None > 0 > >>> from numarray import strings > >>> x = strings.array(['a','b']) > >>> x == None > TypeError > (And exit from mainloop.) Here's what I get: >>> x == None Traceback (most recent call last): ... ValueError: Must define both shape & itemsize if buffer is None I have a couple comments: 1. It's a nasty looking exception but I think it should be an exception. When 'x' is a CharArray, what that expression means is to compute a boolean array where each element contains the result of a string comparison. IMHO, in the context of arrays, it makes no sense to compare a string with None because it is known in advance that the result will be False. 2. The idiom I think you're looking for is: >>> x is None False This means that the identity of x (basically the object address) is not the same as the identity of the singleton object None. This is useful for testing function parameters where the default is None. Regards, Todd ------------------------------------------------------- This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools! Get your free copy of BEA WebLogic Workshop 8.1 today. http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Compare strings.array with None.: 00025, Shin |
|---|---|
| Next by Date: | Re: extracting a random subset of a vector: 00025, Chris Barker |
| Previous by Thread: | Compare strings.array with None.i: 00025, Shin |
| Next by Thread: | random number facilities in numarray and main Python libs: 00025, Faheem Mitha |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |