我在这一级别的Python方面缺乏经验,但需要为团队项目完成它。
我目前有28个阵列,每个阵列内有28个数据点,看起来与此相似,但要长得多:
grid =[["c","c","c","c","c","c","o","o","-","-","o","-","-","o","-","o","o","-","o","o","o","-","-","-","o","o","o","o"]]
我的目标是将其转换为网格格式,然后像(x,y(坐标系一样使用每个数据点,这样我就可以使用向量方程在其中移动对象。基本上是模拟我想要机器人跟随的动作。
网格可视化示例:
[ . . . . . . . . . . .]
[ . . . . . . . . . . . ]
continues...
如有任何指导,我们将不胜感激!
我欢迎Python和C++的结果。
谢谢!
下面是一个示例
#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;
}
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'