python - numpy vertical array write to text file -


i have 2 5 1 vertical array

x = [[1]      [2]      [3]      [4]      [5]] y = [[92]      [93]      [94]      [95]      [96]] 

i need output(belo) in text file

1 92 2 93 3 94 4 95 5 96 

my script looks this

x= numpy.vstack((z)) y= numpy.vstack((r)) numpy.savetxt('fin_lower.dat', ??, fmt='%.4e') 

any appreciated

make 2 arrays:

in [117]: x=np.arange(1,6).reshape(-1,1)  in [119]: y=np.arange(92,97).reshape(-1,1) 

since 2d, concatenate works nicely; hstack , column_stack.

in [122]: xy=np.concatenate((x,y),axis=1)  in [123]: xy out[123]:  array([[ 1, 92],        [ 2, 93],        [ 3, 94],        [ 4, 95],        [ 5, 96]])  in [124]: xy=np.hstack((x,y)) 

now have 2d array (5 rows, 2 col) can saved in desired format:

in [126]: np.savetxt('test.txt',xy) in [127]: cat test.txt 1.000000000000000000e+00 9.200000000000000000e+01 2.000000000000000000e+00 9.300000000000000000e+01 3.000000000000000000e+00 9.400000000000000000e+01 4.000000000000000000e+00 9.500000000000000000e+01 5.000000000000000000e+00 9.600000000000000000e+01  in [128]: np.savetxt('test.txt',xy, fmt='%.4e') in [129]: cat test.txt 1.0000e+00 9.2000e+01 2.0000e+00 9.3000e+01 3.0000e+00 9.4000e+01 4.0000e+00 9.5000e+01 5.0000e+00 9.6000e+01  in [131]: np.savetxt('test.txt',xy, fmt='%d')     in [132]: cat test.txt 1 92 2 93 3 94 4 95 5 96 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -