In [1]:
import numpy as np

In [2]:
with open('data/src/sample.txt') as f:
    print(f.read())


11 12 13 14
21 22 23 24
31 32 33 34

In [3]:
a = np.loadtxt('data/src/sample.txt')

In [4]:
print(type(a))


<class 'numpy.ndarray'>

In [5]:
print(a)


[[11. 12. 13. 14.]
 [21. 22. 23. 24.]
 [31. 32. 33. 34.]]

In [6]:
print(a.dtype)


float64

In [7]:
with open('data/src/sample.csv') as f:
    print(f.read())


11,12,13,14
21,22,23,24
31,32,33,34

In [8]:
# print(np.loadtxt('data/src/sample.csv'))
# ValueError: could not convert string to float: '11,12,13,14'

In [9]:
print(np.loadtxt('data/src/sample.csv', delimiter=','))


[[11. 12. 13. 14.]
 [21. 22. 23. 24.]
 [31. 32. 33. 34.]]

In [10]:
a = np.loadtxt('data/src/sample.csv', delimiter=',', dtype='int64')

In [11]:
print(a)


[[11 12 13 14]
 [21 22 23 24]
 [31 32 33 34]]

In [12]:
print(a.dtype)


int64

In [13]:
with open('data/src/sample_header_index.csv') as f:
    print(f.read())


,a,b,c,d
ONE,11,12,13,14
TWO,21,22,23,24
THREE,31,32,33,34

In [14]:
a = np.loadtxt('data/src/sample_header_index.csv', delimiter=',', dtype='int64',
               skiprows=1, usecols=[1, 2, 3, 4])

In [15]:
print(a)


[[11 12 13 14]
 [21 22 23 24]
 [31 32 33 34]]