Answers for "convert matrix string to matrix python"

0

convert matrix string to matrix python

arr = '[[1, 2], [3, 4], [5, 6]]'
num_set = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
arr_list = list(arr)

matrix = []
row = []

for i in range(0, len(arr_list)):
    try:
        if(len(row) == 2):
            matrix.append(row)
            row = []
        if(int(arr_list[i]) in num_set):
            row.append(int(arr_list[i]))
    except:
        continue

print(matrix)
Posted by: Guest on September-04-2020

Code answers related to "convert matrix string to matrix python"

Python Answers by Framework

Browse Popular Code Answers by Language