From: Joachim S. <li...@js...> - 2004-04-02 23:31:53
|
* Fernando Perez [2004-04-02 02:15]: > Joachim Saul wrote: > > >How often does it happen that you have an empty array, which you > >need to test for? Certainly not as frequently as in case of a > >list. > > Well, just these days I'm working with code where I'm precisely using that > kind of check, relying on Numeric's behavior. But I know that with > potentially nested structures, it's probably best to be explicit and do all > checks via things like: > > if len(a) > > and > > if a==0 But what would a==0 return? A boolean? An array of booleans? An array if integers? The way it is evaluated now in Numeric is pretty clear, though there could be other evaluations. For instance, if a==1: might be understood as "if a is everywhere one" or "if the length of vector a is one", etc. The current meaning is "if a is anywhere one", which may not be intuitive under all circumstances, but as long as it is the well defined behaviour, I simply don't see the need to change or forbid that. Nested structures are an important argument against keeping compatibility with Python list behaviour. For instance >>> if []: print "True" >>> if [[]]: print "True" True Which perfectly makes sense in Python, but an equivalent behaviour of a numeric array would be complete humbug. Thus, I don't think that it would make any sense to emulate Python list behaviour, rather I would support keeping the *existing* Numeric behaviour. Cheers, Joachim |