def map_data(data_map, axis_num): data_map = np.max(data_map, axis=axis_num) data_map -= data_map.min() data_map = data_map / data_map.max() data_map = np.array(data_map * 255, dtype=np.uint8) return data_map 转为c++
时间: 2024-03-02 13:52:37 浏览: 32
这是一段 Python 代码,转换为 C++ 的代码如下:
```cpp
#include <vector>
#include <algorithm>
std::vector<std::vector<int>> map_data(std::vector<std::vector<int>> data_map, int axis_num) {
int rows = data_map.size();
int cols = data_map[0].size();
if (axis_num == 0) {
for (int i = 0; i < rows; ++i) {
int max_val = *std::max_element(data_map[i].begin(), data_map[i].end());
for (int j = 0; j < cols; ++j) {
data_map[i][j] = (int)(255.0 * (data_map[i][j] - 0.0) / (max_val - 0.0));
}
}
}
else {
for (int j = 0; j < cols; ++j) {
int max_val = 0;
for (int i = 0; i < rows; ++i) {
max_val = std::max(max_val, data_map[i][j]);
}
for (int i = 0; i < rows; ++i) {
data_map[i][j] = (int)(255.0 * (data_map[i][j] - 0.0) / (max_val - 0.0));
}
}
}
return data_map;
}
```
注意,这段代码的数据类型是 `std::vector<std::vector<int>>`,需要先将输入数据转换为 `std::vector<std::vector<int>>` 类型,然后调用这个函数进行处理。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.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)
![](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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)