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

Benjamin Root ben.root@ou....
Sat Jan 14 16:25:05 CST 2012


On Sat, Jan 14, 2012 at 4:16 PM, Benjamin Root <ben.root@ou.edu> wrote:

> On Sat, Jan 14, 2012 at 4: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')
>>
>> It might be more consistent to return '0' instead, as in
>>
>> In [3]: zeros(2, int).astype('S')
>> Out[3]:
>> array(['0', '0'],
>>       dtype='|S24')
>>
>> Chuck
>>
>>
> Whatever it should be, numpy is currently inconsistent:
>
> >>> np.empty(2, 'S')
> array(['0', '\xd4'],
>       dtype='|S1')
> >>> np.zeros(2, 'S')
>
> array(['', ''],
>       dtype='|S1')
> >>> np.ones(2, 'S')
> array(['1', '1'],
>       dtype='|S1')
>
> I would expect '0''s for the call to zeros() and empty strings for the
> call to empty().
>
> Ben Root
>
>
On the other hand, it is fairly standard to assume that the values in the
array returned by empty() to be random, uninitialized junk.  So, maybe
empty()'s current behavior is ok, but certainly zeros()'s and ones()'s
behaviors need to be looked at.

Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120114/4cd78e7a/attachment.html 


More information about the NumPy-Discussion mailing list