[Numpy-discussion] dtype for a single char

sam tygier samtygier at yahoo.co.uk
Wed Mar 3 16:14:11 EST 2010


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?



More information about the NumPy-Discussion mailing list