[Numpy-discussion] np.zeros(2, 'S') returns empty strings.
Paul Anton Letnes
paul.anton.letnes at gmail.com
Sun Jan 15 02:39:50 EST 2012
On 15. jan. 2012, at 01:21, josef.pktd at gmail.com wrote:
> On Sat, Jan 14, 2012 at 5:25 PM, Benjamin Root <ben.root at ou.edu> wrote:
>> On Sat, Jan 14, 2012 at 4:16 PM, Benjamin Root <ben.root at ou.edu> wrote:
>>>
>>> On Sat, Jan 14, 2012 at 4:12 PM, Charles R Harris
>>> <charlesr.harris at 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')
>
>
>
> I would be surprised if zeros is not an empty string, since an empty
> string is the "zero" for string addition.
> multiplication for strings doesn't exist, so ones can be anything even
> literally '1'
My python disagrees.
In [1]: 2 * 'spam ham '
Out[1]: 'spam ham spam ham '
Not sure what the element-wise numpy array equivalent would be, though.
Paul
More information about the NumPy-Discussion
mailing list