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 [email protected]
test.py
Description: application/python
_______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
