Re: [Numpy-discussion] String manipulation summary

2009-07-27 Thread Christopher Barker
Chris Colbert wrote: > what machine spec are you using? Dual 2Ghz PPC OS-X 10.4. Python2.5, numpy 1.3.0rc1 (hmm -- I should upgrade that!) > Using your last function line2array5 WITH float conversion, i get the > following timing on a mobile quad core extreme: > > In [24]: a = np.arange(100).a

Re: [Numpy-discussion] String manipulation summary

2009-07-27 Thread Chris Colbert
what machine spec are you using? Using your last function line2array5 WITH float conversion, i get the following timing on a mobile quad core extreme: In [24]: a = np.arange(100).astype(str).tostring() In [25]: a Out[25]: '012345678911223344556677

[Numpy-discussion] String manipulation summary

2009-07-27 Thread Christopher Barker
Hi all, When I first saws this problem: reading in a fixed-width text file as numbers, it struck me that you really should be able to do it, and do it well, with numpy by slicing character arrays. I got carried away, and worked out a number of ways to do it. Lastly was a method inspired by a

Re: [Numpy-discussion] String manipulation

2009-07-22 Thread David Goldsmith
By the way, Chris, what's it gonna take to get you contributing to the doc? ;-) DG --- On Wed, 7/22/09, Christopher Barker wrote: > From: Christopher Barker > Subject: Re: [Numpy-discussion] String manipulation > To: "Discussion of Numerical Python" > Date: Wedn

Re: [Numpy-discussion] String manipulation

2009-07-22 Thread Christopher Barker
Stéfan van der Walt wrote: You cannot use view on an array scalar, so you'll have to convert to an array first: x = x.reshape((1,)) x.view('S1') Bingo! Thanks, Stéfan. I don't know why one can't uwe view on a scalar -- there is still a dat pointer isn't there?, and it can be reshaped. Butno

Re: [Numpy-discussion] String manipulation

2009-07-22 Thread Stéfan van der Walt
2009/7/21 Christopher Barker : > In [35]: line > Out[35]: '-1.00E+00-1.00E+00-1.00E+00-1.00E+00 > 1.25E+00 1.25E+00' > > In [36]: a = np.array(line) > > In [37]: a > Out[37]: > array('-1.00E+00-1.00E+00-1.00E+00-1.00E+00 1.25E+00 > 1.25E+00', >      

Re: [Numpy-discussion] String manipulation

2009-07-21 Thread David Goldsmith
--- On Tue, 7/21/09, Christopher Barker wrote: > but now when I try to split it up: > > In [38]: a = a.view(dtype='S13') > > I get: > > ValueError: new type not compatible with array. > > Shouldn't that work? > > -Chris Submit an enhancement ticket. ;-) DG ___

Re: [Numpy-discussion] String manipulation

2009-07-21 Thread Christopher Barker
David Goldsmith wrote: > Hi, Chris. Look at this, _I'm_ answering one of _your_ questions > (correctly, I hope): maybe ;-) > --- On Tue, 7/21/09, Christopher Barker > wrote: >> I don't see why: >> >> np.array('a string', dtype='S1') >> >> results in a length (1,) array, for instance. > Well,

Re: [Numpy-discussion] String manipulation

2009-07-21 Thread David Goldsmith
Hi, Chris. Look at this, _I'm_ answering one of _your_ questions (correctly, I hope): --- On Tue, 7/21/09, Christopher Barker wrote: > I don't see why: > > np.array('a string', dtype='S1') > > results in a length (1,) array, for instance. > > Actually, I think I do -- numpy is treating the

Re: [Numpy-discussion] String manipulation

2009-07-21 Thread Christopher Barker
Pierre GM wrote: > On Jul 20, 2009, at 3:44 PM, Christopher Barker wrote: >> ... >> Is there a cleaner way to do this? > Yes. np.lib._iotools.LineSplitter and/or np.genfromtxt Great, thanks -- though the underscore in _iotools implies that this isn't supposed to be general purpose tools. Also,

Re: [Numpy-discussion] String manipulation

2009-07-21 Thread Pierre GM
On Jul 21, 2009, at 3:16 AM, Nils Wagner wrote: >> >> Er, there's already something like that: >> np.lib._iotools.LineSplitter > > Great. I didn't know about that. > > Your examples are very useful. > > IMHO the examples should be added to > > http://www.scipy.org/Cookbook/InputOutput > > to attra

Re: [Numpy-discussion] String manipulation

2009-07-21 Thread Nils Wagner
On Tue, 21 Jul 2009 02:56:28 -0400 Pierre GM wrote: > > On Jul 21, 2009, at 2:42 AM, Nils Wagner wrote: >> >> Fixed-length fields are quite common e.g. in the area of >> Finite Element pre/postprocessing. >> Therefore It would be nice to have a function like >> line2array in numpy. >> Comments

Re: [Numpy-discussion] String manipulation

2009-07-20 Thread Pierre GM
On Jul 20, 2009, at 3:44 PM, Christopher Barker wrote: > ... > Is there a cleaner way to do this? > > -Chris Yes. np.lib._iotools.LineSplitter and/or np.genfromtxt ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailma

Re: [Numpy-discussion] String manipulation

2009-07-20 Thread Pierre GM
On Jul 21, 2009, at 2:42 AM, Nils Wagner wrote: > > Fixed-length fields are quite common e.g. in the area of > Finite Element pre/postprocessing. > Therefore It would be nice to have a function like > line2array in numpy. > Comments ? Er, there's already something like that: np.lib._iotools.LineS

Re: [Numpy-discussion] String manipulation

2009-07-20 Thread Nils Wagner
On Mon, 20 Jul 2009 12:44:23 -0700 Christopher Barker wrote: > Nils Wagner wrote: >> How can I split the second line in such a way that I get >> >> ['-1.00E+00', '-1.00E+00', '-1.00E+00', >> '-1.00E+00', '1.25E+00', '1.25E+00'] >> >> instead of >> >> ['-1.00E+00-1

Re: [Numpy-discussion] String manipulation

2009-07-20 Thread Christopher Barker
Nils Wagner wrote: How can I split the second line in such a way that I get ['-1.00E+00', '-1.00E+00', '-1.00E+00', '-1.00E+00', '1.25E+00', '1.25E+00'] instead of ['-1.00E+00-1.00E+00-1.00E+00-1.00E+00', '1.25E+00', '1.25E+00'] It looks lik

Re: [Numpy-discussion] String manipulation

2009-07-20 Thread Nils Wagner
On Mon, 11 May 2009 10:48:14 -0400 Alan G Isaac wrote: > On 5/11/2009 8:36 AM Nils Wagner apparently wrote: >> I would like to split strings made of digits after eight >> characters each. > > > [l[i*8:(i+1)*8] for i in range(len(l)/8)] > > Alan Isaac > >

Re: [Numpy-discussion] String manipulation

2009-05-11 Thread Alan G Isaac
On 5/11/2009 8:36 AM Nils Wagner apparently wrote: > I would like to split strings made of digits after eight > characters each. [l[i*8:(i+1)*8] for i in range(len(l)/8)] Alan Isaac ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://

Re: [Numpy-discussion] String manipulation

2009-05-11 Thread Alan G Isaac
On 5/11/2009 8:03 AM Nils Wagner apparently wrote: line_a > '12345678abcdefgh12345678' > Is it possible to split line_a such that the output > is > > ['12345678', 'abcdefgh', '12345678'] More of a comp.lang.python question, I think: out = list() for k, g in groupby('123abc456',lambda x: x.

Re: [Numpy-discussion] String manipulation

2009-05-11 Thread Sebastien Binet
hi, > here is my workaround. > > from numpy import arange > line_a = '11.122.233.3' # without > separator > line_b = '11.1 22.2 33.3' # including space > as a delimiter > > div, mod = divmod(len(line_a),8) > liste = [] > for j in arange(0,div): > liste.append(li

Re: [Numpy-discussion] String manipulation

2009-05-11 Thread Nils Wagner
On Mon, 11 May 2009 15:03:02 +0200 Sebastien Binet wrote: > On Monday 11 May 2009 14:36:17 Nils Wagner wrote: >> On Mon, 11 May 2009 14:25:46 +0200 >> >> Francesc Alted wrote: >> > A Monday 11 May 2009, Nils Wagner escrigué: >> >> Hi all, >> >> >> >> Please consider two strings >> >> >> >> >>

Re: [Numpy-discussion] String manipulation

2009-05-11 Thread Sebastien Binet
On Monday 11 May 2009 14:36:17 Nils Wagner wrote: > On Mon, 11 May 2009 14:25:46 +0200 > > Francesc Alted wrote: > > A Monday 11 May 2009, Nils Wagner escrigué: > >> Hi all, > >> > >> Please consider two strings > >> > >> >>> line_a > >> > >> '12345678abcdefgh12345678' > >> > >> >>> line_b > >>

Re: [Numpy-discussion] String manipulation

2009-05-11 Thread Nils Wagner
On Mon, 11 May 2009 14:25:46 +0200 Francesc Alted wrote: > A Monday 11 May 2009, Nils Wagner escrigué: >> Hi all, >> >> Please consider two strings >> >> >>> line_a >> >> '12345678abcdefgh12345678' >> >> >>> line_b >> >> '12345678 abcdefgh 12345678' >> >> >>> line_b.split() >> >> ['12345678', 'a

Re: [Numpy-discussion] String manipulation

2009-05-11 Thread Francesc Alted
A Monday 11 May 2009, Francesc Alted escrigué: > Although regular expressions seems a bit thought to learn, they will ^^^ --> tough :-\ -- Francesc Alted "One would expect people to feel threatened by the 'giant brains or machines that think'. In

Re: [Numpy-discussion] String manipulation

2009-05-11 Thread Francesc Alted
A Monday 11 May 2009, Nils Wagner escrigué: > Hi all, > > Please consider two strings > > >>> line_a > > '12345678abcdefgh12345678' > > >>> line_b > > '12345678 abcdefgh 12345678' > > >>> line_b.split() > > ['12345678', 'abcdefgh', '12345678'] > > Is it possible to split line_a such that the output

[Numpy-discussion] String manipulation

2009-05-11 Thread Nils Wagner
Hi all, Please consider two strings >>> line_a '12345678abcdefgh12345678' >>> line_b '12345678 abcdefgh 12345678' >>> line_b.split() ['12345678', 'abcdefgh', '12345678'] Is it possible to split line_a such that the output is ['12345678', 'abcdefgh', '12345678'] Nils

Re: [Numpy-discussion] String manipulation

2009-04-23 Thread Francesc Alted
A Thursday 23 April 2009, Nils Wagner escrigué: > Hi all, > > How can I obtain the position of the minus sign within the > following string ? > > >>> liste[1] > > '1.5-te' That's easy by using basic weaponery in Python: In [8]: liste[1].find('-') Out[8]: 3 In [9]: liste[1][3] Out[9]: '-' -- F

[Numpy-discussion] String manipulation

2009-04-23 Thread Nils Wagner
Hi all, How can I obtain the position of the minus sign within the following string ? >>> liste[1] '1.5-te' Nils ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion