此代码设置为读取两列数据,然后将第一列打印到第一个 numpy 数组中,然后将第二列打印到第二个 numpy 数组中。
def read2coldata(filename):
import numpy
b = []
f = open(filename,"r")
lines = f.readlines()
f.close()
for line in lines:
a = line.split()
for i in a:
b.append(i)
return (numpy.array(b[::2]),numpy.array(b[1::2]))
然而,这给出了:
(array(['1.5', '8', '16', '17'], dtype='|S3'), array(['4', '5', '6', '6.2'], dtype='|S3'))
我如何摆脱dtype="|S3"
零件以离开:
(array(["1.5","8","16","17"], array(["4","5","6","6.2"])