Posts

Showing posts from 2018

Python Matrix

Image
What is a matrix? A matrix is a two-dimensional data structure. In real-world tasks you often have to store rectangular data table. The table below shows the marks of three students in different subjects. S.No Student Name Science English History Arts Maths 1 Roy 80 75 85 90 95 2 John 75 80 75 85 100 3 Dave 80 80 80 90 95 Such tables are called matrices or two-dimensional arrays. In python any table can be represented as a list of lists (a list, where each element is in turn a list). For example: A = [[ 'Roy' , 80 , 75 , 85 , 90 , 95 ],[ 'John' , 75 , 80 , 75 , 85 , 100 ],[ 'Dave' , 80 , 80 , 80 , 90 , 95 ]] In the above example A represents a 3*6 matrix where 3 is number of rows and 6 is number of columns. How to create a matrix? In python, matrix is a nested list. A list is created by placing all the items (elements) inside a square bracket  [ ] , separated by commas. Example 1