How to reshape this array with numpy?
Question: My file looks like this

    
    
    3.766204987418e+00  3.016098278453e+00  2.882128625608e+00  2.789447648712e+00  2.704276250639e+00 
     2.540138572067e+00  2.318587560199e+00  2.272640952350e+00  2.138794921589e+00 
    

I have also code to read it

    
    
    import numpy as np
    
    zxyr=[]
    
    with open('det.txt') as f:
        zxyr=list(f)
    
    c=np.asarray(zxyr)
    print c.shape
    print len(c)
    

which produces

    
    
    (2,)
    2
    

How to reshape array to have (9,) shape?

EDIT I have tried

    
    
    import numpy as np      
    
    c = np.loadtxt('det.txt')
    print (c.shape)
    

BUt

    
    
    Traceback (most recent call last):
      File "kiev.py", line 3, in <module>
        c = np.loadtxt('det.txt')
      File "/usr/lib/python2.7/dist-packages/numpy/lib/npyio.py", line 856, in loadtxt
        X = np.array(X, dtype)
    ValueError: setting an array element with a sequence.
    


Answer: As @B.M. said in the comments you need to use `np.loadtxt`. As shown below:

    
    
    import numpy as np      
    
    c = np.loadtxt('mytextfile.txt)
    print (c.shape)
    

This gets the data from the file and puts it into a numpy array. If the text
file in my example is the same as yours then it will have the shape `(9,)` as
you require.

Another method you can do is the following:

    
    
    with open('mytextfile.txt') as f:
        content = f.readlines()
    

