[SciPy-user] Convert a string list to array ?
Tue Feb 26 14:47:11 CST 2008
On Tue, Feb 26, 2008 at 02:09:02PM -0600, Nathan Bell wrote:
> On Tue, Feb 26, 2008 at 1:50 PM, Stef Mientki <firstname.lastname@example.org> wrote:
> > Is there a better (more elegant) way ?
> > And maybe the string list was even the wrong first step,
> > the datafile I'm reading looks like this:
> > 254 48 57
> > 58 52 53
> > 58 51 54
> > 254 32 32
> > 32 32 32
> > So there might even be better ways to start ?
> Try numpy.fromfile()
> A = fromfile( 'myfile.txt', dtype=int, sep=' ')
> This should be very fast and memory efficient.
Isn't numpy.loadtxt designed to handle this? With fromfile I get all data in a
1d array and have to do an additional reshape() if the data in the file
represents a 2d array.
More information about the SciPy-user