Add a list to a numpy array
Question: 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?


Answer: If your file `data.txt` is

    
    
    1 2 3 4
    1 2 3 4
    1 2 3 4
    1 2 3 4
    1 2 3 4
    1 2 3 4
    

All you need to do is

    
    
    >>> import numpy as n
    >>> data_array = n.loadtxt("data.txt")
    >>> data_array
    
    array([[1., 2., 3., 4.],
           [1., 2., 3., 4.],
           [1., 2., 3., 4.],
           [1., 2., 3., 4.],
           [1., 2., 3., 4.],
           [1., 2., 3., 4.]])
    

