gpt4 book ai didi

C++ Armadillo reshape 一个只有一维大小的矩阵

转载 作者:行者123 更新时间:2023-11-28 01:44:50 25 4
gpt4 key购买 nike

使用 Armadillo ,当我只指定一维大小时如何 reshape 矩阵?

Matlab documentation ,有这样的功能的这个例子:

Reshape a 6-by-6 magic square matrix into a matrix that has only 3 columns. Specify [] for the first dimension size to let reshape automatically calculate the appropriate number of rows.

A = magic(6);
B = reshape(A,[],3);

The result is a 12-by-3 matrix, which maintains the same number of elements (36) as the original 6-by-6 matrix. The elements in B also maintain their columnwise order from A.

Armadillo 如何做到这一点?

最佳答案

您可以使用 .size() 获取矩阵元素的总数并自行计算维度。示例:

B = reshape(A, A.size()/3, 3);

关于C++ Armadillo reshape 一个只有一维大小的矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45573298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com