python load array

Solutions on MaxInterview for python load array by the best coders in the world

showing results for - "python load array"
Carl
24 Nov 2018
1>>> from numpy import *
2>>>
3>>> data = loadtxt("myfile.txt")                       # myfile.txt contains 4 columns of numbers
4>>> t,z = data[:,0], data[:,3]                         # data is 2D numpy array
5>>>
6>>> t,x,y,z = loadtxt("myfile.txt", unpack=True)                  # to unpack all columns
7>>> t,z = loadtxt("myfile.txt", usecols = (0,3), unpack=True)     # to select just a few columns
8>>> data = loadtxt("myfile.txt", skiprows = 7)                    # to skip 7 rows from top of file
9>>> data = loadtxt("myfile.txt", comments = '!')                  # use '!' as comment char instead of '#'
10>>> data = loadtxt("myfile.txt", delimiter=';')                   # use ';' as column separator instead of whitespace
11>>> data = loadtxt("myfile.txt", dtype = int)                     # file contains integers instead of floats