Python 3.7, Numpy: I need to save a 3rd-order object, which was created using numpy. It is a list of arrays, to be precise. The arrays get matrix-multiplied to vectors using numpy.dot() after being loaded. Is there a way to save this object (for example in a .txt-file) without it losing its format?
If I simply put the object into a .txt-file using .write() I convert it into a string. I could of course convert that back into the float array, but before I do that I wanted to know if there is a simpler or more efficient way of doing it.
That would look something like this:
BigObject = []
for i in (0, Size1):
BigObject.append(np.random.uniform(-1, 1, (Size2, Size3)))
with open("test.txt", "w+") as output:
output.write(str(BigObject))
How I save it and
with open("test.txt", "r") as input:
NewBigObject = input.read()
how I read it.
This does give me back a string for the NewBigObject
which I cannot matrix-multiply to a vector.
The way the BigArray gets saved is not relevant. I just want to know if there is a smart way of saving it without losing the format. Now I could run a series of split()
and float()
commands to get the original object back. But can I do this faster or more elegantly?