i am trying to get rid if unnecessary space on a numpy grid
This is my code:
import numpy as np
def make_grid():
grid = np.full((6, 7), " ")
return grid
grid = make_grid()
print(grid)
this is what it outputs full and empty:
[['1' '1' '1' '1' '1' '1' '1']
['1' '1' '1' '1' '1' '1' '1']
['1' '1' '1' '1' '1' '1' '1']
['1' '1' '1' '1' '1' '1' '1']
['1' '1' '1' '1' '1' '1' '1']
['1' '1' '1' '1' '1' '1' '1']]
[[' ' ' ' ' ' ' ' ' ' ' ' ' ']
[' ' ' ' ' ' ' ' ' ' ' ' ' ']
[' ' ' ' ' ' ' ' ' ' ' ' ' ']
[' ' ' ' ' ' ' ' ' ' ' ' ' ']
[' ' ' ' ' ' ' ' ' ' ' ' ' ']
[' ' ' ' ' ' ' ' ' ' ' ' ' ']]
what i would like full and empty:
[['1''1''1''1''1''1''1']
['1''1''1''1''1''1''1']
['1''1''1''1''1''1''1']
['1''1''1''1''1''1''1']
['1''1''1''1''1''1''1']
['1''1''1''1''1''1''1']]
[[' '' '' '' '' '' '' ']
[' '' '' '' '' '' '' ']
[' '' '' '' '' '' '' ']
[' '' '' '' '' '' '' ']
[' '' '' '' '' '' '' ']
[' '' '' '' '' '' '' ']]
how do i get rid of those spaces.
CodePudding user response:
You could do this:
import numpy as np
def make_grid():
board = np.full((6, 7), " ")
return board
grid = make_grid()
print(str(grid.tolist()).replace("', '", "''").replace("], [", "]\n ["))