[Matrix-SIG] Numeric arrays / assertions / truth testing

Bruce Duncan bsd@scripps.edu
Mon, 6 Apr 1998 16:23:14 -0700 (PDT)


Greetings,

Is it documented how Numeric treats assertions, e.g.,

assert myarray

The behavior, although consistent, is somewhat counter-intuitive:
Numeric checks for identity to zero.   I suggest an exposition of
this in the next round of documentation.

Python 1.5 (#63, Mar 11 1998, 14:53:33) [C] on irix5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import Numeric
>>> a = Numeric.array([1,2,3.0])
>>> assert a
>>> b = Numeric.array([0.0,0.0])
>>> assert b
Traceback (innermost last):
  File "<stdin>", line 1, in ?
AssertionError
>>> len(a)
3
>>> len(b)
2

I was using
   assert myarray
when I meant
   assert myarray != None

-bsd-


Bruce Duncan
The Scripps Research Institute 
bsd "is located at" scripps "in the domain" edu  # anti spam...