如何将数据存储为np.array格式

时间:2016-02-22 09:13:35

标签: python numpy

我想将数据存储到np.array中,通过读取行​​,它该怎么办?

def convert_hdf5(lines,idx):
        num_lines = len(lines)
        if num_lines == 0:
                return
        with h5py.File("aa" + str(idx) + '.h5', 'w') as f:
                for i in range(num_lines):
                        line = lines[i]
                        fields = line.split(",")
                        x = np.array(fields[1:],np.float32)
                        y = np.array(fields[0], np.float32)
                f['label'] = x1
                f['data'] = y1

如何将x,y存储到更大的x1,y1?

1 个答案:

答案 0 :(得分:1)

我不理解输入数据lines。 我们假设输入数据为:

lines = ['1, 2, 3, 4', '5, 6, 7, 8']

将此数据存储为int

for line in lines:
    fields = line.split(",")
    x.append(fields[1:])
    y.append(fields[0])
x_array = np.asarray(x, dtype=int)
y_array = np.asarray(y, dtype=int)