我有 data_pressure ,这是一个numpy数组的列表,例如:
array([ 268752., 26222., 261152., 260958.]),
array([ 123433., 98239., 98932.]),
array([ 2893789., 872398., 92839., 9283982., 7632762., 547627.,])
每个阵列都有不同的长度 .
我用Python的csv模块保存到这个数组列表:
import csv
csvfile = "csvfile.csv"
with open(csvfile, "w") as output:
writer = csv.writer(output, lineterminator='\n')
for line in data_pressure:
writer.writerow(line)
一切都像魅力一样,但正如我所读到的那样
import csv
data = []
with open('csvfile.csv', 'rb') as csvfile:
spamreader = csv.reader(csvfile)
for row in spamreader:
data.append(np.asarray(row))
我明白了
array([ '268752.0', '26222.0', '261152.0', '260958.0']),
array([ '123433.0', '98239.0', '98932.0']),
array([ '2893789.0', '872398.0', '92839.0', '9283982.0', '7632762.0', '547627.0',])
然后,任何数组中的每个值都是字符串类型而不是浮点数 .
有没有办法规避这个问题?