-1

I've coded a program that gives me data in tabular form (using tabulate) in python:

from tabulate import tabulate

matrix=[[1,2,3,4],[5,6,7,8]]

print(tabulate(matrix))

It gives me this output:

image

Now say that I want to split this table in 2 such that it gives:

image

How would I do that?

agg199
  • 43
  • 5

1 Answers1

0

Here is a function I found here to split a normal array into two arrays. In the for loop, we split every one of the arrays in the matrix with the function. When you want to get the first part change the 1 to a 0.

from tabulate import tabulate

def split_list(a_list):
    half = len(a_list)//2
    return a_list[:half], a_list[half:]

matrix=[[1,2,3,4],[5,6,7,8]]
new_matrix = []

for arr in matrix:
    new_matrix.append(split_list(arr)[1]) #Replace this 1 with a 0

print(tabulate(new_matrix))

or just

from tabulate import tabulate

def split_list(a_list):
    half = len(a_list)//2
    return a_list[:half], a_list[half:]

matrix=[[1,2,3,4],[5,6,7,8]]
new_matrix = split_list(matrix[1])


print(tabulate(new_matrix))
Frederick
  • 450
  • 4
  • 22