[PYTHON MATRIX-SIG] array()

Timothy A. Hochberg hochberg@wwa.com
Tue, 13 May 1997 15:10:25 -0500 (CDT)




On Tue, 13 May 1997, Konrad Hinsen wrote:

> >     I have two ways to do what I want:
> > 
> > 	a = array(['a', 'bcd', 'fg', 'h'], 'O')[:,0]
> >     
> >     or
> > 
> > 	a = zeros(4, typecode='O')
> > 	a[:] = ['a', 'bcd', 'fg', 'h']
> > 
> >     Both work, but seem perverse to me.
> 
> I'd use the following:
> 
>    a = array(4*[None])
>    a[:] = ['a', 'bcd', 'fg', 'h']

a = array(['a', 'bcd', 'fg', 'h', None])[:-1]

also works for people obsessed with doing things in 1 line....;)

But, in the case of strings:

I just got done looking at arrayobject.c, and I'm convinced this is
unintentional, it looks like strings are not supposed to be treated as
sequence types when making an object array. It seems as if discover_depth
should be called as

    nd=discover_depth(s,99, type == PyArray_OBJECT ||type == 'O'  )

rather than

    nd=discover_depth(s,99, type == PyArray_OBJECT)

in Array_FromSequence. It's probably a result of string being treated
one way sometimes, and another way other times that the string
weirdness above appears. Note that

    a = array(['a', 'bcd', 'fg', 'h'], chr(10))

works as you'd expect right now given that chr(10) is PyArray_OBJECT.

[SNIP]


-tim


_______________
MATRIX-SIG  - SIG on Matrix Math for Python

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