0

谁能告诉我关于 Matrix Reshape(int newChannels, int newRows) 函数的信息。什么是参数 newChannels 的意思?我的代码如下

Matrix<Double> A = new Matrix<Double>(4, 4);
Matrix<Double> reshapeMatrix;
reshapeMatrix = A.Reshape(1, 16);

此代码工作正常。但

 reshapeMatrix = A.Reshape(2, 8);

此代码成功运行,但 reshapeMatrix 大小不正确,我无法使用 reshapeMatrix 数据。

谁能解释为什么会这样?我如何对任何大小的矩阵使用 reshape() 函数?

4

1 回答 1

1

As you noticed, Matrix.Reshape takes newChannels as first argument. A matrix can have several channels, for example color channels (1 for grayscale, 3 for RGB). What Reshape does is that it reshapes both channels, columns and rows of the matrix.

What you want to achieve with reshapeMatrix = A.Reshape(2, 8); is probably to reshape the matrix so that it has 2 columns and 8 rows, but still one color channel. Or am I wrong?

If that is what you want to achieve, the correct way to do it is:

reshapeMatrix = A.Reshape(1, 8);

As there are 16 elements and 8 rows, the number of columns will automatically be 2. The number of channels is still kept to one.

The reason why reshapeMatrix = A.Reshape(1, 16); works is because you specify that you should keep having one color channel. And with 16 rows, the only option left is to have one column.

于 2013-03-28T15:38:06.310 回答