Right now I'm writing a function that reads data from a file, with the goal being to add that data to a numpy array and return said array.
I would like to return the array as a 2D array, however I'm not sure what the complete shape of the array will be (I know the amount of columns, but not rows). What I have right now is:
columns = _____
for line in currentFile:
currentLine = line.split()
data = np.zeros(shape=(columns),dtype=float)
tempData = []
for i in range(columns):
tempData.append(currentLine[i])
data = np.concatenate((data,tempdata),axis=0)
However, this makes a 1D array.
Essentially what I'm asking is:
Is there any way to have add a python list as a row to a numpy array with a variable amount of rows?
numpy.loadtxtto read write into a numpy array. Similarly you can usenumpy.genfromtxt