如何简单数组转换成二维阵列(矩阵)中的Fortran? [英] How to convert simple array into two-dimensional array(matrix) in Fortran?

查看:740
本文介绍了如何简单数组转换成二维阵列(矩阵)中的Fortran?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不从文件中读取数据和所有数据存储在一个一维阵列。
然而,一些数据我有一个矩阵(2维数组)来存储我怎样才能做到这一点?

I had to read data from a file and store all data in a one dimensional array. However, Some data I have to store in a matrix (2 dimensional array) How Can I do this?

例如,如果我的数据是 1X7 阵列 [1,2,3,1,5,2,8] 和第一至第六属于矩阵 2×3 我怎么能存储在一个新的数组变量?

For example if my data is 1x7 array [1,2,3,1,5,2,8] and the first to 6th belong to a matrix 2x3 how can I store in a new array variable?

推荐答案

假设你的7个元素的数组被称为 array7 ,那么下面前pression应返回一个包含 array7

Suppose that your 7-element array is called array7, then the following expression should return a 2x3 array containing the first 6 elements of array7

reshape(array7(1:6),[2,3])

如果说放元素融入到新的数组中的顺序错误,请尝试

If that puts the elements into the new array in the wrong order, try

reshape(array7(1:6),[2,3],order=[2,1])

请注意,我已经在第二版中使用了一个名为可选参数,还有一个可选的参数(),这将是,默认情况下,第三个参数重塑

Note that I've used a named optional argument in the second version, there is another optional argument (pad) which would be, by default, the 3rd argument to reshape.

这篇关于如何简单数组转换成二维阵列(矩阵)中的Fortran?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆