>>> s = """np.array([[0 0 1 0 0 0 0 1 0 0 1 1], ... [1 0 0 1 1 0 0 0 0 0 1 1 0 0 1 1 0 1 0 0 1 0 1 0 0 1 ... 0 0 0 0 1 0 1 1 0 1 0 0 0], ... [0 1 0 0 0 1 0 1 1 0 0 0 1 1 0 1 1 0 ... 0 1 0 1 0 0 0]])""" >>> import re >>> print(re.sub(r"(\d) ", r"\1, ", s)) np.array([[0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1], [1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0], [0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0 0, 1, 0, 1, 0, 0, 0]])