range_x = 100 range_y=100 x, y = np.meshgrid(np.arange(range_x), np.arange(range_y)) # np.savetxt('reshape_data.txt', x, delimiter=' ', fmt="%i") x_o = x - range_x / 2 y_o = y - range_y / 2 x_i = x - dx y_i = y - dy 转C++
时间: 2024-01-12 18:04:14 浏览: 28
这段代码的C++实现如下:
```cpp
int range_x = 100;
int range_y = 100;
vector<vector<int>> x(range_x, vector<int>(range_y));
vector<vector<int>> y(range_x, vector<int>(range_y));
for (int i = 0; i < range_x; i++) {
for (int j = 0; j < range_y; j++) {
x[i][j] = i;
y[i][j] = j;
}
}
vector<vector<int>> x_o(range_x, vector<int>(range_y));
vector<vector<int>> y_o(range_x, vector<int>(range_y));
vector<vector<int>> x_i(range_x, vector<int>(range_y));
vector<vector<int>> y_i(range_x, vector<int>(range_y));
for (int i = 0; i < range_x; i++) {
for (int j = 0; j < range_y; j++) {
x_o[i][j] = x[i][j] - range_x / 2;
y_o[i][j] = y[i][j] - range_y / 2;
x_i[i][j] = x[i][j] - dx;
y_i[i][j] = y[i][j] - dy;
}
}
```
其中,使用了vector来存储矩阵,通过双重循环遍历来实现numpy中的arange()函数的功能,最后分别计算了x_o、y_o、x_i和y_i。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)