# create more than once 2d array in python

how to make 2d array in python with input from user which user can input how much array 2d needed. example :

input :

2 -> indicates how many arrays you want 2 -> indicate size of array(2 for rows and column set default 3) 2 3 4 5 6 7 3 4 5 6 7 8 9 1 2 3

and output: print it all

i try but i can’t get right answer in my code. that’s my code:

A = int(input("enter how many matrix create: ")) for i in range(A): B = int(input("enter size : ")) matrix = [] print("enter number: ") for j in range(B): a =[] for k in range(3): a.append(input()) matrix.append(a) print(matrix)

## Answer

Here’s my solution:

print("Enter the number of arrays:") K = int(input()) # This stores all the arrays array = [] for i in range(K): print("Enter the number of rows and columns you want:") rows = int(input()) columns = 3 # You don't actually need to use this in your code matrix = [] print("Start entering the rows:") for j in range(rows): matrix.append(input().split()) array.append(matrix)

**Note:** This stores the elements in a string form, so instead of the number 1, it stores `'1'`

(as a string)

To convert the input into multiple integers, you can use the `list`

and `map`

functions like this:

print("Enter the number of arrays:") K = int(input()) # This stores all the arrays array = [] for i in range(K): print("Enter the number of rows and columns you want:") rows = int(input()) columns = 3 # Because it's the default value matrix = [] print("Start entering the rows:") for j in range(rows): matrix.append(list(map(int, input().split()))) # Converts the input into a list of integers array.append(matrix)