-1

I am inexperienced at this level of Python but need to complete it for a team project.

I currently have 28 arrays consisting of 28 data points inside each array which will look similar to this but way longer:

grid =[["c","c","c","c","c","c","o","o","-","-","o","-","-","o","-","o","o","-","o","o","o","-","-","-","o","o","o","o"]]

My goal is to get this into a grid-looking format and then use each data point like an (x,y) coordinate system so I can move an object through them using vector equations. Basically simulating the motion I want a robot to follow.

Grid visual example:

[ . . . . . . . . . . .] 
[ . . . . . . . . . . . ]
continues...

Any guidance will be much appreciated, please!

I welcome results in Python and C++.

Thank you!

Marek R
  • 32,568
  • 6
  • 55
  • 140
dingoyum
  • 25
  • 4
  • if you know how to write a loop that prints individual characters then this can be done. Please show your attempt and pick one language – 463035818_is_not_an_ai Mar 02 '22 at 14:24
  • 1
    You haven't asked a question - please read [ask] and [mre]. Searching SO often helps - how about [Print a list of strings in a grid format - Python](https://stackoverflow.com/questions/32460832/print-a-list-of-strings-in-a-grid-format-python), or [Dynamic string formatting in python](https://stackoverflow.com/questions/26311406/dynamic-string-formatting-in-python), or [Print a Grid in Python without any package importing](https://stackoverflow.com/questions/66729509/print-a-grid-in-python-without-any-package-importing) – wwii Mar 02 '22 at 14:51
  • Search example - `python print grid site:stackoverflow.com` – wwii Mar 02 '22 at 14:52

2 Answers2

1

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;
}
Pepijn Kramer
  • 9,356
  • 2
  • 8
  • 19
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])

result will be

'c'
loran d
  • 88
  • 1
  • 7