c++ - 堆栈 std::vectors 以生成矩阵,类似于 numpy.vstack
问题描述
有没有办法堆叠,例如,两个std::vectors
大小为 N,以生成每 N 列 2 行的矩阵?类似于 Python 的 np.vstack 函数?不使用低效的vectors ( std::vector<std::vector<type>>
) 解决方案或array 数组?
解决方案
只需使用一维数组。多维数组语法是邪恶的。
const int width = 1024;
const int height = 768;
vector<float> matrix(0,width*height);
float getCell(int row, int col)
{
return matrix[row * width + col];
}
float setCell(int row, int col, float val)
{
matrix[row * width + col] = val;
}
推荐阅读
- javascript - 你如何将参数传递给react-intl中的defineMessages?
- time-series - 预测客户下个月的购买情况
- javascript - HTML AJAX 向后端发送空对象
- linux - 已执行 Cron 脚本但没有输出
- wordpress - 启用 WEBSITES_ENABLE_APP_SERVICE_STORAGE 后 WordPress for Linux Web App 丢失
- xamarin - Xamarin Forms FFImageLoading 角转换
- assembly - EMU8086显示屏(黑屏)
- python - 为什么我会收到关于 scipy 稀疏列切片的警告?
- git - Phabricator SSH
- c++ - c++中的文件结构