[Numpy-discussion] String manipulation
David Goldsmith
d_l_goldsmith at yahoo.com
Wed Jul 22 14:38:45 EDT 2009
By the way, Chris, what's it gonna take to get you contributing to the doc? ;-)
DG
--- On Wed, 7/22/09, Christopher Barker <Chris.Barker at noaa.gov> wrote:
> From: Christopher Barker <Chris.Barker at noaa.gov>
> Subject: Re: [Numpy-discussion] String manipulation
> To: "Discussion of Numerical Python" <numpy-discussion at scipy.org>
> Date: Wednesday, July 22, 2009, 11:33 AM
> 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 matter, now I have a one liner that splits a
> string up into fixed fields, and returns a float array of
> the numbers in those fields:
>
> np.array((line,)).view(dtype='S%i'%field_len).astype(np.float)
>
> I suspect this is faster than the list comp method, though
> I haven't tested it -- I"ll leave that to someone that
> actually has this problem to solve ;-)
>
> I've enclosed a bit of test code with a few other
> approaches as well.
>
> -Chris
>
>
>
>
> -- Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R
> (206) 526-6959 voice
> 7600 Sand Point Way NE (206)
> 526-6329 fax
> Seattle, WA 98115
> (206) 526-6317 main
> reception
>
> Chris.Barker at noaa.gov
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
More information about the NumPy-Discussion
mailing list