The easiest way to save your array, including metadata (dtype, dimensions), is to use numpy.save() and numpy.load() :
a = array([[False, True, False], [ True, False, True], [False, True, False], [ True, False, True], [False, True, False]], dtype=bool) numpy.save("data.npy", a) numpy.load("data.npy") # array([[False, True, False], # [ True, False, True], # [False, True, False], # [ True, False, True], # [False, True, False]], dtype=bool)
a.tofile() and numpy.fromfile() will work, but do not save the metadata. You need to pass dtype=bool to fromfile() and get a one-dimensional array, which should be reshape() d to its original form.
Sven marnach
source share