fastest way to read a text file in to a numpy array
Cody Piersall
cody.piersall at gmail.com
Tue Jun 28 10:37:55 EDT 2016
On Tue, Jun 28, 2016 at 8:45 AM, Heli <hemla21 at gmail.com> wrote:
> Hi,
>
> I need to read a file in to a 2d numpy array containing many number of lines.
> I was wondering what is the fastest way to do this?
>
> Is even reading the file in to numpy array the best method or there are better approaches?
>
numpy.genfromtxt[1] is a pretty robust function for reading text files.
If you're generating the file from a numpy array already, you should
use arr.save()[2] and numpy.load()[3].
[1]: http://docs.scipy.org/doc/numpy/reference/generated/numpy.genfromtxt.html
[2]: http://docs.scipy.org/doc/numpy/reference/generated/numpy.save.html
[3]: http://docs.scipy.org/doc/numpy/reference/generated/numpy.load.html
Cody
More information about the Python-list
mailing list