<br><br><div class="gmail_quote">On Sat, Jan 14, 2012 at 5:21 PM,  <span dir="ltr"><<a href="mailto:josef.pktd@gmail.com">josef.pktd@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Sat, Jan 14, 2012 at 5:25 PM, Benjamin Root <<a href="mailto:ben.root@ou.edu">ben.root@ou.edu</a>> wrote:<br>
> On Sat, Jan 14, 2012 at 4:16 PM, Benjamin Root <<a href="mailto:ben.root@ou.edu">ben.root@ou.edu</a>> wrote:<br>
>><br>
>> On Sat, Jan 14, 2012 at 4:12 PM, Charles R Harris<br>
>> <<a href="mailto:charlesr.harris@gmail.com">charlesr.harris@gmail.com</a>> wrote:<br>
>>><br>
>>> This sort of makes sense, but is it the 'correct' behavior?<br>
>>><br>
>>> In [20]: zeros(2, 'S')<br>
>>> Out[20]:<br>
>>> array(['', ''],<br>
>>>       dtype='|S1')<br>
>>><br>
>>> It might be more consistent to return '0' instead, as in<br>
>>><br>
>>> In [3]: zeros(2, int).astype('S')<br>
>>> Out[3]:<br>
>>> array(['0', '0'],<br>
>>>       dtype='|S24')<br>
<br>
<br>
<br>
</div>I would be surprised if zeros is not an empty string, since an empty<br>
string is the "zero" for string addition.<br>
multiplication for strings doesn't exist, so ones can be anything even<br>
literally '1'<br>
<br>
>>> a = np.zeros(5,'S4')<br>
>>> a[:] = 'b'<br>
>>> reduce(lambda x,y: x+y, a)<br>
'bbbbb'<br>
<br>
<br>
>>> a = np.zeros(1,'S100')<br>
>>> for i in range(5): a[:] = a.item() + 'a'<br>
...<br>
>>> a<br>
array(['aaaaa'],<br>
      dtype='|S100')<br>
<br>
<br>
just as a logical argument, I have no idea what's practical since last<br>
time I tried to use numpy strings, I didn't find string addition and<br>
went back to double and triple list comprehension.<br>
<br></blockquote><div><br>I don't think it was quite so cleverly reasoned out ;) The functions works as expected for object arrays, but that is the only exception. For all other types the allocated space is simply filled with zero bytes. Too bad this isn't done in python like ones, it would be easier to fix.<br>
<br><snip><br><br>Chuck <br></div></div>