C# 中的 Matlab reshape 命令等效于什么?如何将 C# 2D 浮点数组转换为 3D 浮点数组?

What is the equivalent of the Matlab reshape command in C#? How do I convert a C# 2D float array to a 3D float array?

在 Matlab 中我有这个

2darray = fread(fid, [160 304*304], 'float32');
3darray = reshape(2darray, [160 304 304]);

在 C# 中我有这个:

float[,] 2darray = new float[160, 304 * 304];

using (BinaryReader reader = new BinaryReader(File.OpenRead("path")))
{
    for(int i = 0; i < 160; i++)
    {
        for (int j = 0; j < 304 * 304; j++)
            2darray[i, j] = reader.ReadSingle();
    }
}

从这里(在 C# 中),如何将 2D 浮点数组重塑为 3D 浮点数组?

当你不能把穆罕默德带到山上时,就把山带到穆罕默德面前。

        static void Main(string[] args)
        {
            float[,,] dArray = new float[160, 304, 304];

            using (BinaryReader reader = new BinaryReader(File.OpenRead("path")))
            {
                for(int i = 0; i < 160; i++)
                {
                    for (int j = 0; j < 304; j++)
                    {
                        for (int k = 0; k < 304; k++)
                        {
                            dArray[i, j, k] = reader.ReadSingle();
                        }
                    }
                }
            }
        }