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

Robert Kern robert.kern@gmail....
Wed Apr 21 14:55:27 CDT 2010


On Wed, Apr 21, 2010 at 10:49, Éric Depagne <edepagne@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.

No, not really.

You can make a 1D array of records (they're not really tuples, though
we print them like tuples). That's almost as good.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the SciPy-User mailing list