列表中是否存在numpy.save的模拟?

时间:2018-03-09 06:57:44

标签: python python-3.x numpy

是否有像numpy.save这样的函数,但它将列表(不是数组)保存到二进制文件中?

假设我要保存包含数字和字符的异构列表

    BigInteger G = new BigInteger("1001", 2);
    BigInteger M = new BigInteger("101110", 2);
    BigInteger R = M.remainder(G);

如果我用numpy.save保存它,然后加载它

a = [1,2,3,4,'a']

然后我只得到一个字符列表:

np.save('a.npy',a)
b = np.load('a.npy').tolist()

1 个答案:

答案 0 :(得分:0)

这肯定有用

lst = [1, 1.2, 'a']

with open("lst.list", "w") as outfile:
    outfile.write(str(lst))

with open("lst.list", "r") as infile:
    loaded = eval(infile.read())

print(loaded)  # [1, 1.2, 'a']