[PYTHON MATRIX-SIG] empty array
Groma Geza
GROMA@everx.szbk.u-szeged.hu
Fri, 22 Mar 1996 16:11:05 MET
Konrad Hinsen writes:
> 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?
-------------------------------------------------------------------
>>> from Numeric import *
>>> array([])
Traceback (innermost last):
File "<stdin>", line 1, in ?
TypeError: illegal argument type for built-in operation
>>>
-------------------------------------------------------------------
> A single "empty array" does not make sense,
> since there can be many empty arrays that differ in shape. Matlab can
> get away with that because its matrix concept is much more limited.
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
In v0.35 this returns false. The equality can be tested by
len(a.notEqual(b).nonzero()) == 0
but I personally prefer the previous style. None is a 'general empty
object', something similar could be introduced for arrays, too.
Another problem is that an empty array is not a printable object:
--------------------------------------------------------------
>>> array([0]).nonzero()
Traceback (innermost last):
File "<stdin>", line 1, in ?
File "./PrettyPrinter.py", line 28, in arrayToString
max_str_len = max(len(str(maximum.reduce(data))),
ArrayError: can't take anything from an empty array
>>>
-----------------------------------------------------------------
Geza I. Groma
Institute of Biophysics
Biological Research Centre of Hungarian Academy of Sciences
Szeged, Hungary
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================