0

I am currently working on training a neural network and the preprocessing step takes a while to go through, especially when I want to tweak the parameter of my network structure. My input data consist of a list of numpy arrays, stored in 4 different variables. Is possible to store these list of numpys into local files, such that I just could load them and start the training rather than loading the raw files and begin preprocess that.

user7654132
  • 123
  • 10

1 Answers1

2

You can save numpy arrays using numpy.save (or numpy.savez for multiple arrays at once) and load them again using numpy.load.

e.g. saving arrays:

import numpy
test_array_1 = numpy.ones([5, 6]) #creating a test array
test_array_2 = numpy.zeros([6, 7]) #creating a test array
numpy.savez("testfile.npz", test_array_1=test_array_1, test_array_2=test_array_2) #saving my two test arrays

e.g. loading arrays

import numpy
data = numpy.load("testfile.npz") #loading the two arrays into a variable called 'data'
print(data["test_array_1"]) #using one array directly
test_array_2 = data["test_array_2"] #assigning one to a varibale
Ari Cooper-Davis
  • 3,374
  • 3
  • 26
  • 43