[Numpy-discussion] Failing to understand vectorize behavior

Bryan Van de Ven bryanv@enthought....
Wed Jan 9 10:32:07 CST 2008


otypes needs to be set for this to work.


In [19]: vstrip = vectorize( string.strip, otypes=[object])

In [20]: s = ['  aaaaaaaaaaaaaa  ' , ' bbbbbbbbbbbbbbbbbb  ', ' 
cccccccccccccccccc ']

In [21]: vstrip(s)
Out[21]: array([aaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc], 
dtype=object)



lorenzo bolla wrote:
> Yes, 32 bits.
> On a 64 bits machine, I get 8 characters long strings like you.
> L.
> 
>  
> On 1/9/08, *David Huard* <david.huard@gmail.com 
> <mailto:david.huard@gmail.com>> wrote:
> 
>     Lorenzo,
> 
>     2008/1/9, lorenzo bolla <lbolla@gmail.com <mailto:lbolla@gmail.com>>:
> 
>         I don't think it's expected: mine are cropped to 4 characters!
> 
> 
> 
>     I am on a 64 bit machine. Are you on a 32 bit one ?
>      
>     In [101]: vstrip = vectorize(
>     string.strip)                                                                                                                                     
> 
> 
>         In [102]: s = ['  aaaaaaaaaaaaaa  ' , ' bbbbbbbbbbbbbbbbbb  ',
>         '   cccccccccccccccccc ']  
>         In [103]:
>         vstrip(s)                                                                      
> 
>         Out[103]:                                                                                
> 
>         array(['aaaa', 'bbbb',
>         'cccc'],                                                          
>              
>         dtype='|S4')                                                                       
> 
>          
>         You can obviously use "map", instead.
> 
> 
>     I'll do that,
>      
>     Thanks,
> 
> 
>     David
> 
>         In [104]: map(string.strip,
>         s)                                            
>         Out[104]: ['aaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbb',
>         'cccccccccccccccccc']   
>                                                                                   
> 
>         hth,
>         L.
>          
>          
>         On 1/9/08, *David Huard* < david.huard@gmail.com
>         <mailto:david.huard@gmail.com>> wrote:
> 
>             Hi all,
> 
>             I'm having trouble understanding the behavior of vectorize
>             on the following example:
> 
>             > >> import string
>             > >> from numpy import vectorize
> 
>             > >> vstrip = vectorize( string.strip)
>             > >> s = ['  aaaaaaaaaaaaaa  ' , ' bbbbbbbbbbbbbbbbbb  ', '  
>             cccccccccccccccccc ']
>             > >> vstrip(s)
>             array(['aaaaaaaa', 'bbbbbbbb', 'cccccccc'],
>                   dtype='|S8')
> 
>             where all strings are cropped to 8 characters.
>             Is this expected ?
> 
> 
>             Thanks,
> 
>             David
> 
> 
> 
>             _______________________________________________
>             Numpy-discussion mailing list
>             Numpy-discussion@scipy.org <mailto:Numpy-discussion@scipy.org>
>             http://projects.scipy.org/mailman/listinfo/numpy-discussion
>             <http://projects.scipy.org/mailman/listinfo/numpy-discussion>
> 
> 
> 
> 
>         -- 
>         Lorenzo Bolla
>         lbolla@gmail.com <mailto:lbolla@gmail.com>
>         http://lorenzobolla.emurse.com/
>         _______________________________________________
>         Numpy-discussion mailing list
>         Numpy-discussion@scipy.org <mailto:Numpy-discussion@scipy.org>
>         http://projects.scipy.org/mailman/listinfo/numpy-discussion
> 
> 
> 
>     _______________________________________________
>     Numpy-discussion mailing list
>     Numpy-discussion@scipy.org <mailto:Numpy-discussion@scipy.org>
>     http://projects.scipy.org/mailman/listinfo/numpy-discussion
>     <http://projects.scipy.org/mailman/listinfo/numpy-discussion>
> 
> 
> 
> 
> -- 
> Lorenzo Bolla
> lbolla@gmail.com <mailto:lbolla@gmail.com>
> http://lorenzobolla.emurse.com/
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion



More information about the Numpy-discussion mailing list