Answers for "python matrix input"

0

Take Matrix input from user in Python

# Taking one row at a time with space-separated values.
# And converting each of them to using map and int function.

matrix = []
for i in range(row):
   col = list(map(int, input().split()))
   matrix.append(col)
print(matrix)

'''
Input :
1 2
3 4
Output :
[[1, 2], [3, 4]]
'''
Posted by: Guest on September-30-2021
2

scanning 2d array in python

If you want to take n lines of input where each line contains m space separated integers like:

1 2 3
4 5 6 
7 8 9 

a=[] // declaration 
for i in range(0,n):   //where n is the no. of lines you want 
 a.append([int(j) for j in input().split()])  // for taking m space separated integers as input
Posted by: Guest on July-07-2020
1

how to input 2-d array in python

matrix = [input().split() for i in range(no_of_rows)] # if only row is given and the number of coloumn has to be decide by user
matrix= [[input() for j in range(no_of_cols)] for i in range(no_of_rows)] # if both row and coloumn has been taken as input from user
Posted by: Guest on April-27-2020

Python Answers by Framework

Browse Popular Code Answers by Language