如何将数组转换为 28 行 x 28 列的网格,可以用作 (x,y) 坐标系?

发布于 2025-01-11 03:13:20 字数 1468 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绮烟 2025-01-18 03:13:20

这是一个例子

#include <array>
#include <iostream>

// create a reuable alias for an array of an array of values
// for this example it will be a 5x5 grid.
using grid_t = std::array<std::array<char, 5>, 5>;

// pass grid by const reference
// So C++ will not copy the grid (pass by value)
// and the const means show_grid can't modify the content.
void show_grid(const grid_t& grid)
{
    // use a range based for loop to loop over the rows in the grid
    for (const auto& row : grid)
    {
        // use another to loop over the characters in a row
        for (const auto c : row) std::cout << c;
        std::cout << "\n";
    }
}

int main()
{
    // setup a grid
    grid_t grid
    { {
        { 'a', '-' ,'o', 'a', 'a' },
        { '-', 'o' ,'o', 'a', 'a' },
        { 'o', 'a' ,'-', 'a', 'o' },
        { 'o', 'a' ,'-', '-', 'o' },
        { 'a', '-' ,'o', '-', 'a' }
    } };

    show_grid(grid);
    return 0;
}

Here is an example

#include <array>
#include <iostream>

// create a reuable alias for an array of an array of values
// for this example it will be a 5x5 grid.
using grid_t = std::array<std::array<char, 5>, 5>;

// pass grid by const reference
// So C++ will not copy the grid (pass by value)
// and the const means show_grid can't modify the content.
void show_grid(const grid_t& grid)
{
    // use a range based for loop to loop over the rows in the grid
    for (const auto& row : grid)
    {
        // use another to loop over the characters in a row
        for (const auto c : row) std::cout << c;
        std::cout << "\n";
    }
}

int main()
{
    // setup a grid
    grid_t grid
    { {
        { 'a', '-' ,'o', 'a', 'a' },
        { '-', 'o' ,'o', 'a', 'a' },
        { 'o', 'a' ,'-', 'a', 'o' },
        { 'o', 'a' ,'-', '-', 'o' },
        { 'a', '-' ,'o', '-', 'a' }
    } };

    show_grid(grid);
    return 0;
}
彻夜缠绵 2025-01-18 03:13:20
import numpy as np 
grid =[["c","c","c","c","c","c","o","o","-","-","o","-","-","o","-","o","o","-","o","o","o","-","-","-","o","o","o","o"]]
np_grid = np.array(grid)
a = np_grid.reshape(4,7)
print (a[0,1])

结果将是

'c'
import numpy as np 
grid =[["c","c","c","c","c","c","o","o","-","-","o","-","-","o","-","o","o","-","o","o","o","-","-","-","o","o","o","o"]]
np_grid = np.array(grid)
a = np_grid.reshape(4,7)
print (a[0,1])

result will be

'c'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文