[Numpy-discussion] np.zeros(2, 'S') returns empty strings.

Nathaniel Smith njs@pobox....
Sun Jan 15 02:15:41 CST 2012


On Sat, Jan 14, 2012 at 2:12 PM, Charles R Harris
<charlesr.harris@gmail.com> wrote:
> This sort of makes sense, but is it the 'correct' behavior?
>
> In [20]: zeros(2, 'S')
> Out[20]:
> array(['', ''],
>       dtype='|S1')

I think of numpy strings as raw fixed-length byte arrays (since, well,
that's what they are), so I would expect np.zeros to return all-NUL
strings, like it does. (Not just 'empty' strings, which just means the
first byte is NUL -- I expect all-NUL.) Maybe I've spent too much time
working with C data structures, but that's my $0.02 :-)

-- Nathaniel


More information about the NumPy-Discussion mailing list