[Matrix-SIG] bug in array constructor for type 'O'

Marc Keller mkeller@cybercable.fr
Mon, 20 Dec 1999 14:28:30 +0100


Charles G Waldman wrote:

> Just noticed this:
>
> >>> a=array(["foo","bar","baz"])
> >>> a
> array([[f, o, o],
>        [b, a, r],
>        [b, a, z]],'c')
>
> This is slightly odd, but I can rationalize it, since each of the
> strings "looks like" an array of characters.
>
> But if I try to force the arraytype to "O" (Python Object)
> I get:
>
> >>> a=array(["foo","bar","baz"],'O')
> >>> a
> array([[foo , foo , foo ],
>        [bar , bar , bar ],
>        [baz , baz , baz ]],'O')
>
> This just looks like a bug.
>
> _______________________________________________
> Matrix-SIG maillist  -  Matrix-SIG@python.org
> http://www.python.org/mailman/listinfo/matrix-sig

Seems to be a bug...
But there is some logic here: stop the level of structure analysis when
type differ:
For example if
l= >>> l= 'floor', 'bar', 'ba'
>>> b=array(l,'O')
results in
>>> b
array([[floor , floor , floor , floor , floor ],
       [bar , bar , bar , bar , bar ],
       [ba , ba , ba , ba , ba ]],'O')
with
>>> b=array((None,)+l)
we get
>>> b
array([None , floor , bar , ba ],'O')
>>>