Numpy saving and loading introduces zeros in the middle of every element - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Numpy saving and loading introduces zeros in the middle of every element (/thread-23111.html) |
Numpy saving and loading introduces zeros in the middle of every element - DreamingInsanity - Dec-11-2019 I am do a simple numpy saving and loading test with this code: a = np.array([[[10,10,10], [10, 10, 10]], [[10,10,10], [10,10,10]]]) print(a) f = io.BytesIO() np.save(f, a) co = codecs.encode(f.getvalue(), 'bz2') cd = codecs.decode(co, 'bz2') np.save(f, cd) f.seek(0) n = np.frombuffer(np.load(f, allow_pickle=True), dtype=np.int32) print(n) #print(n.reshape(a.shape))Of course, 'a' outputs: However, 'n' outputs: The shape isn't an issue since I can reshape it later. What is the issue is all the zeros that are being introduced between every number.I am using this line to remove them: n = np.array(n)[::2]It works fine, but I have a feeling that in my actually program, its going to accidentally remove a zero its not supposed to, or have some other problem like that. How do I get these zeros not to come about? |