我想将数据存储到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 中?
我不明白输入数据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)