简体   繁体   English

将二维数组另存为 txt 文件

[英]Save 2D array as a txt file

In my simulation i compute an array x with "dimensions"在我的模拟中,我用“维度”计算了一个数组 x

np.shape(x)

---> (50,80)

To my understanding this is a two dimensional array with 50 rows and 80 columns.据我了解,这是一个 50 行 80 列的二维数组。 When i try save x as a csv file i get an error:当我尝试将 x 保存为 csv 文件时,出现错误:

np.savetxt('values.csv',[x])

--> ValueError: Expected 1D or 2D array, got 3D array instead

How can x be a 3D array? x 怎么可能是 3D 阵列? Its described by two indices (row,column) and therefore is two dimensional or not?它由两个索引(行,列)描述,因此是二维的吗?

Remove the square brackets from x .x中删除方括号。 This is converting it to a list of one item - the array.这是将其转换为一个项目的列表 - 数组。

np.savetxt('values.csv',x)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM