[PYTHON MATRIX-SIG] Re: empty array

Konrad HINSEN hinsenk@ere.umontreal.ca
Mon, 25 Mar 1996 08:29:36 -0500


>  
>         > array() should accept empty lists in its arguments. Then array([])
>         > would be a rank-1 array of length zero, array([[],[]]) a rank-2 array
>         > of shape (2,0) and so on. 
> 
> That is what I expected, too, but it does not work, at least on my 
> system (built from v0.35). What is wrong in this code?

I know it doesn't work. When I wrote "it should work" I didn't mean
"I think it works", but "I think it ought to work". Keep in mind
that the array module is neither finished nor bug-free.

> Even if array([]) were correct, that would be useful only to create 
> an empty array, and not to test it. In TestUtils.py I found a simple 
> and natural way to check the equality of array a and b:
> 
> 	     a.notEqual(b).nonzero() == None

I must confess that I never understood what nonzero() is good
for. Now I am beginning to realize its use. The name is
rather misleading...

Anyway, to test the equality of two arrays, of course
   a == b
ought to work. Currently it seems to be equivalent to
   a is b
which is against standard Python conventions. Unfortunately
there is no way to give a reasonable meaning to a > b
and a < b, but they are much less important in practice.

Supposing that a == b does what everybody expects it to
do, you can then use it to test for a specific form
of an empty array by writing
    a == array([])
    a == array([[]])
and so on. To test for general emptyness, i.e. to test if
an array has zero elements, you can write
    ravel(a) == array([])

> Another problem is that an empty array is not a printable object:

I know, but there is no point in trying to fix this as long
as many operations don't work properly on empty arrays. The
expression
   maximum.reduce(data)
for example should not raise an error if "data" is empty,
but return the smallest representable number of the type
of "data".

-------------------------------------------------------------------------------
Konrad Hinsen                     | E-Mail: hinsenk@ere.umontreal.ca
Departement de chimie             | Tel.: +1-514-343-6111 ext. 3953
Universite de Montreal            | Fax:  +1-514-343-7586
C.P. 6128, succ. Centre-Ville     | Deutsch/Esperanto/English/Nederlands/
Montreal (QC) H3C 3J7             | Francais (phase experimentale)
-------------------------------------------------------------------------------

=================
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================