Closed TerenceCYJ closed 5 years ago
There's an easier way: change h5f.create_dataset('dataset_2', data = names) into h5f.create_dataset('dataset2', data = np.string(names)) after importing numpy.
Regards
@TerenceCYJ @Max-Fu There is a pull request #11 using Python 3.6. I don't know whether it's compatible with Python 2.7. The code in this part is written as follows:
h5f = h5py.File(output, 'w')
h5f.create_dataset('dataset_1', data=feats)
h5f.create_dataset('dataset_2', data=[name.encode("utf-8") for name in names])
h5f.close()
Do you have time to test it whether it's compatible with Python 2.7?
Sorry, I have only tested on Python 3.6 (currently I don't have Python 2.7 on my server).
Regards.
@Max-Fu Thank you for your test. When you test it on Python 3.6, do you have make some changes? or it just have this problem addressed here?
@willard-yuan I have only changed the part addressed above.
报错代码:h5f.create_dataset('dataset_2', data = names) 原因:create_dataset 只接受 ascii 的数据,如果你是Python3或者python使用utf-8的编码就会报错。 解决办法:
h5f.create_dataset('dataset_2', data = names)
namess = [] for j in names: namess.append(j.encode()) h5f.create_dataset('dataset_2', data = namess) h5f.close()