Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python numpy垂直数组写入文本文件_Python_Arrays_Numpy_Vertical Text - Fatal编程技术网

Python numpy垂直数组写入文本文件

Python numpy垂直数组写入文本文件,python,arrays,numpy,vertical-text,Python,Arrays,Numpy,Vertical Text,我有两个5乘1的垂直阵列 x = [[1] [2] [3] [4] [5]] y = [[92] [93] [94] [95] [96]] 我需要在文本文件中输出(belo) 1 92 2 93 3 94 4 95 5 96 我的脚本是这样的 x= numpy.vstack((z)) y= numpy.vstack((r)) numpy.savetxt('fin_lower.dat', ??, fmt='%.4e

我有两个5乘1的垂直阵列

x = [[1]
     [2]
     [3]
     [4]
     [5]]
y = [[92]
     [93]
     [94]
     [95]
     [96]]
我需要在文本文件中输出(belo)

1 92
2 93
3 94
4 95
5 96
我的脚本是这样的

x= numpy.vstack((z))
y= numpy.vstack((r))
numpy.savetxt('fin_lower.dat', ??, fmt='%.4e')
非常感谢您的帮助

制作两个阵列:

In [117]: x=np.arange(1,6).reshape(-1,1) 
In [119]: y=np.arange(92,97).reshape(-1,1)
由于它们是二维的,
串联
工作得很好<代码>hstack和
列堆栈

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))
现在我有了一个2d数组(5行,2列),可以按所需格式保存:

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
制作两个阵列:

In [117]: x=np.arange(1,6).reshape(-1,1) 
In [119]: y=np.arange(92,97).reshape(-1,1)
由于它们是二维的,
串联
工作得很好<代码>hstack和
列堆栈

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))
现在我有了一个2d数组(5行,2列),可以按所需格式保存:

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

谢谢,谢谢你的帮助!谢谢,谢谢你的帮助!