[Numpy-discussion] dtype for a single char
Robert Kern
robert.kern at gmail.com
Thu Mar 4 10:26:37 EST 2010
On Thu, Mar 4, 2010 at 02:34, sam tygier <samtygier at yahoo.co.uk> wrote:
> Robert Kern wrote:
>> On Wed, Mar 3, 2010 at 15:14, sam tygier <samtygier at yahoo.co.uk> wrote:
>>> Hello
>>>
>>> today i was caught out by trying to use 'a' as a dtype for a single character. a simple example would be:
>>>
>>>>>> array([('a',1),('b',2),('c',3)], dtype=[("letter", "a"), ("number", "i")])
>>> array([('', 1), ('', 2), ('', 3)],
>>> dtype=[('letter', '|S0'), ('number', '<i4')])
>>>
>>> the fix seems to be using 'a1' instead
>>>
>>>>>> array([('a',1),('b',2),('c',3)], dtype=[("letter", "a1"), ("number", "i")])
>>> array([('a', 1), ('b', 2), ('c', 3)],
>>> dtype=[('letter', '|S1'), ('number', '<i4')])
>>>
>>> this seems odd to me, as other types eg 'i' and 'f' can be used on their own. is there a reason for this?
>>
>> Other types have a sensible default determined by the platform.
>
> I don't understand. char has sensible default size on my platform (and all the others i am familiar with), 1 byte.
'S' is not char.
--
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 NumPy-Discussion
mailing list