[SciPy-User] numpy.array of mixed type.

Charles R Harris charlesr.harris at gmail.com
Wed Apr 21 20:27:14 EDT 2010


On Wed, Apr 21, 2010 at 9:49 AM, Éric Depagne <edepagne at lcogt.net> wrote:

> Hi.
>
> I'd like to create an array that would contain data of two different types:
> str and float64.
>
> I've created a dtype accordingly :
> dt = dtype({'names': ['Type', 'Chisquare'], 'formats': ['S8', float64]})
> then, I initialise my array as follow:
> temp = zeros ((1,1), dtype = dt)
>
> that gives me the following:
> array([[('', 0.0)]],
>      dtype=[('Type', '|S8'), ('Chisquare', '<f8')])
>
> which is almost good.
>
> I'd like to know if it is possible instead of having an array with one
> column
> that will contain a tuple, to create an array with two columns,  the first
> column being a str and the second a float.
>
>
It's not a tuple, it is just displayed that way, it is more like a packed c
structure. But no, you can't have *actual* ndarray columns of different
types. What problem do you have with using the dtype?

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20100421/5155342b/attachment.html>


More information about the SciPy-User mailing list