python - 使用 np.savetxt 将数组保存为列

标签 python numpy

我正在尝试做一些可能非常简单的事情。我想使用'np.savetxt'将三个数组作为列保存到一个文件中当我尝试这个时

x = [1,2,3,4]
y = [5,6,7,8]
z = [9,10,11,12]

np.savetxt('myfile.txt', (x,y,z), fmt='%.18g', delimiter=' ', newline=os.linesep)

数组是这样保存的

1 2 3 4
5 6 7 8
9 10 11 12

但我最喜欢的是这个

1 5 9
2 6 10
3 7 11
4 8 12

最佳答案

使用 numpy.c_[] :

np.savetxt('myfile.txt', np.c_[x,y,z])

关于python - 使用 np.savetxt 将数组保存为列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15192847/

相关文章:

python - 类型错误 : can't multiply sequence by non-int of type 'numpy.float64' when trying to solve a 2nd degree polynomial

python - 使用 scipy/numpy 在 python 中进行图像处理的高通滤波器

python - 将 SConstruct 代码划分为一组别名;默认情况下不调用任何代码

python - 具有多个分支的 github 存储库的唯一 git url?

python - 按索引写入多维数组

Python dask_ml 线性回归 多个常量列检测到错误

Python-firebase 与 firebase-storage 一起工作

python - 使用 Mathematica 和 Python 创建图形

python - git Push azure master azure fatal : Not a git repository (or any of the parent directories): . git

python 如何查找从 2019 年 12 月开始并在两个日期列之间向前推进的每个月的天数