0

I want to rewrite/replace a 2d list or numpy array (whatever is easier) in the console: e.g.:

[[_,_,_],
 [_,_,_],
 [x,_,_]]

will be replaced with

[[_,_,_],
 [x,_,_],
 [_,_,_]]

which will be replaced with

[[x,_,_],
 [_,_,_],
 [_,_,_]]

and so on...so it looks like the x is moving across the "board". I already wrote the function that enables me to print the lists one after the other but i would rather replace them in the console output.

thanks in advance for help!

mayool
  • 138
  • 8

1 Answers1

0
import os
import time
import numpy as np

def cls():
    os.system('cls' if os.name=='nt' else 'clear')

x0 = np.array([[0, 0, 0],
               [0, 0, 0],
               [1, 0, 0]])

x1 = np.array([[0, 0, 0],
               [2, 0, 0],
               [0, 0, 0]])

x2 = np.array([[3, 0, 0],
               [0, 0, 0],
               [0, 0, 0]])

print(x0)
time.sleep(1)
cls()
print(x1)
time.sleep(1)
cls()
print(x2)

see How to clear the interpreter console?

Joe
  • 6,758
  • 2
  • 26
  • 47
  • unfortunately it's not working for me. I still get the individual arrays but with a small arrow pointing upwards at the start of the array. is it maybe because i use pycharm? – mayool Feb 26 '18 at 16:53
  • Which operating system? I tried using Spyder, don't have PyCharm to test. Could you try IDLE or your system command prompt? – Joe Feb 26 '18 at 21:19