代码段1
// An highlighted block
import numpy as np
filepath = open('E:/1.txt')
#从文件中读取数据,读取第0列和第1列,要求文件中每一行的列数相等
dataset = np.loadtxt(filepath, delimiter=',',usecols=(0,1))
Xdata = dataset[:, 0]
Ydata = dataset[:, 1]
结果:
>>>dataset
array([[1.11, 3.23],
[2. , 2. ],
[3. , 3. ]])
>>>Xdata
array([1.11, 2. , 3. ])
代码段2(unpack=True)
// An highlighted block
import numpy as np
filepath = open('E:/1.txt')
#从文件中读取数据,读取第0列和第1列,要求文件中每一行的列数相等
dataset = np.loadtxt(filepath, delimiter=',', usecols=(0, 1), unpack=True)
Xdata = dataset[0]
Ydata = dataset[1]
结果:
>>>dataset
array([[1.11, 2. , 3. ],
[3.23, 2. , 3. ]])
>>>Xdata
array([1.11, 2. , 3. ])