Matrix is nothing but a rectangular arrangement of data or numbers. In other words, it is a rectangular array of data or numbers. The horizontal entries in a matrix are called as ‘rows’ while the vertical entries are called as ‘columns’. If a matrix has r number of rows and c number of columns then the order of matrix is given by r x c. Each entries in a matrix can be integer values, or floating values, or even it can be complex numbers.
// 3 x 4 matrix 1 2 3 4 M = 4 5 6 7 6 7 8 9 // 2 x 3 matrix in Python A = ( [ 2, 5, 7 ], [ 4, 7, 9 ] ) // 3 x 4 matrix in Python where entries are floating numbers B = ( [ 1.0, 3.5, 5.4, 7.9 ], [ 9.0, 2.5, 4.2, 3.6 ], [ 1.5, 3.2, 1.6, 6.5 ] )
In Python, we can take a user input matrix in different ways. Some of the methods for user input matrix in Python are shown below:
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 6
Code #2: Using
map() function and
In Python, there exists a popular library called NumPy. This library is a fundamental library for any scientific computation. It is also used for multidimensional arrays and as we know matrix is a rectangular array, we will use this library for user input matrix.
Enter the number of rows:2 Enter the number of columns:2 Enter the entries in a single line separated by space: 1 2 3 1 [[1 2] [3 1]]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- How to take user input for two dimensional (2D) array in PHP ?
- How to Take Input from the User in Golang?
- Take input from stdin in Python
- How to take integer input in Python?
- Python | Numpy matrix.take()
- Python | Get a list as input from user
- How to input multiple values from user in one line in Python?
- How to validate and sanitize user input with PHP?
- User Input in PySimpleGUI
- Taking Input from User in R Programming
- Python | Pandas dataframe.take()
- Python | Pandas TimedeltaIndex.take()
- Python | Pandas Series.take()
- How to take screenshots using python?
- How to take screenshot using Selenium in Python ?
- Create a Python Script Notifying to take a break
- numpy.take() in Python
- DelayQueue take() method in Java with Examples
- What is Hactoberfest and How One Can Take Participate in it?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : mkumarchaudhary06