[Matrix-SIG] NumPy arrays with object typecode

Konrad Hinsen hinsen@cnrs-orleans.fr
Tue, 2 Feb 1999 18:41:06 +0100


> Strangely, NumPy (LLNL v.9) does only seem to allow assigning to slices
> along the second axis, not along the first:

That looks like a bug...

> I also find this counter-intuitive: 
> 
> >>> objArrayFromInits = array(['1','12','123'],'O')
> >>> objArrayFromInits
> array([[1 , 1 , 1 ],
>        [12 , 12 , 12 ],
>        [123 , 123 , 123 ]],'O')
> 
> Is there any efficient way to have the array constructor treat the
> individual strings as objects and not as 1d arrays?

Not in the current NumPy. It generates one dimension for each nesting
level of sequence types, and strings are of course sequence types.
The only way out is to create the array with the right shape
but some other content (e.g. None) and then assign the string values
to the elements individually.

Of course the array constructor could be modified, but
1) that creates compatibility problems and
2) there must be a way to construct character arrays from strings.
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                            | E-Mail: hinsen@cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.55.69
Rue Charles Sadron                       | Fax:  +33-2.38.63.15.17
45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
France                                   | Nederlands/Francais
-------------------------------------------------------------------------------