将一维数组的索引转换为二维数组
converting the index of 1D array into 2D array
如何将一维数组的索引转换为二维数组? 我知道如何将 2D 数组转换为 1D (i*the size of row+j)
.我想要相反的。
您需要知道的是: 2D 数组应该有多少列:假设你有一个 20 列和 10 行的数组(array[20,10]):
int index = 47;
int numberOfColumns = 20;
int column = index % numberOfColumns;
int row = index / numberOfColumns;
// column == 7
// row == 2
你可以做相反的事情。 如果 n 是行的长度,x 是一维索引。您可以像
array[x/n][x%n]
相关文章:
- 将值从二维数组输出到文本文件
- 在二维数组中查找最小值和最大值?
- 转换回二维数组
- 将一维数组转换为二维数组
- 将一维数组的索引转换为二维数组
- 用C++将三维数组转换为二维数组
- 如何将二维数组转换为指针中的指针
- 将一维数组转换为二维数组
- 如何使用malloc从一维数组转换为二维数组
- 用C++将列表转换为对象的二维数组
- 如何在 OpenCV 中从二维数组转换为灰度图像
- 将表示二维数组的 std::vector<std::vector <double> >转换为 cv::Mat
- 在 C++ 中将一维数组转换为二维数组
- 将字符串转换为二维数组
- 在 Mac 中将一维数组转换为二维不起作用
- 如何在不分配内存的情况下将一维数组转换为二维数组
- OpenCV Mat到alglib的真实二维数组转换
- 在matlab中未正确设置二维数组到C++的转换
- 二维数组到指针到指针的转换
- 将ctypes int**转换为numpy二维数组