Easy questions from a python beginner

Grant Edwards invalid at invalid.invalid
Mon Jul 12 10:40:47 EDT 2010


On 2010-07-11, Thomas Jollans <thomas at jollans.com> wrote:
> On 07/11/2010 08:45 PM, wheres pythonmonks wrote:

>> On #3: Sorry this is confusing, but I was browsing some struct array
>> code from numpy, in which one of the columns contained strings, but
>> the type information, supplied in numpy.array's dtype argument,
>> specified the type as a an "object" not a string.

A string is an object.

>> Just wondering why one would do that.
>
> No expert on numpy, but maybe storing object references is cheaper than
> storing strings here ?

Strings are objects.

IIRC, numpy has special homogeneous array types to hold certain scalar
values: byte, int, float, complex.  Those special array types allow
for very efficient storage and operations.

If you want an array of any other type, or a heterogeneous array, then
you use an array of objects and then you can put anything into the
array (including strings).

-- 
Grant Edwards               grant.b.edwards        Yow! The PINK SOCKS were
                                  at               ORIGINALLY from 1952!!
                              gmail.com            But they went to MARS
                                                   around 1953!!



More information about the Python-list mailing list