问题
大多数数据并不是我们自己构造的,而是存在文件当中,需要我们用工具获取。
但是Numpy其实并不适合用来读取和处理数据,因此我们这里了解相关API,以及Numpy不方便的地方即可。
Numpy读取
- genfromtxt(fname[, dtype, comments, …]) Load data from a text file, with missing values handled as specified.
准备数据test.csv:
# 读取数据
test = np.genfromtxt("test.csv", delimiter=',')
返回结果:
array([[ nan, nan, nan, nan],
[ 1. , 123. , 1.4, 23. ],
[ 2. , 110. , nan, 18. ],