#31 Python Tutorial for Beginners | Working with Matrix in Python
Check out our courses: AI Powered DevOps with AWS - Live Course :- https://go.telusko.com/AIDevOps-AWS Coupon: TELUSKO10 (10% Discount) Complete Java Developer Course Batch-4: https://go.telusko.com/Complete4 Coupon: TELUSKO10 (10% Discount) Master Java Spring Development : https://go.telusko.com/masterjava Coupon: TELUSKO20 (20% Discount) Udemy Courses: Spring: https://go.telusko.com/udemyteluskospring Java:- https://go.telusko.com/udemyteluskojava Java Spring:- https://go.telusko.com/Udemyjavaspring Java For Programmers:- https://go.telusko.com/javaProgrammers Python : https://go.telusko.com/udemyteluskopython Git : https://go.telusko.com/udemyteluskogit Docker : https://go.telusko.com/udemyteluskodocker For More Queries WhatsApp or Call on : +919008963671 website : https://courses.telusko.com/ Instagram : https://www.instagram.com/navinreddyofficial/ Linkedin : https://in.linkedin.com/in/navinreddy20 TELUSKO Android App : https://bit.ly/TeluskoApp Discord : https://discord.gg/D8hWe9BqfF Matrix Multiplication Theory : https://goo.gl/omPVAS Watch till 7:12 mins In this lecture we will learn: - What are mutli-dimeansional arrays? - Two-dimensional array in Python - Attributes available with a two-dimensional array - How to convert the dimensions of an array - Matrix in Python - How to convert an array into a matrix? - Functions used with a matrix #1 - If a list contains multiple elements of the same type, then it is known as an array. - When an array contains another array inside it, then it is known as a two-dimensional array. - Two- dimensional array can be defined as an array within another array. - It is a collection of rows and columns. Syntax of a two-dimensional array:- arr= array([ [arr1], [arr2] ]) #2 Attributes with two-dimensional arrays:- - dtype attribute returns the data type of the data with which you are working. - ndim attribute gives the number of dimensions of an array and also gives the rank to an array. e.g, if it is a single-dimensional array then it will return 1 if three-dimensional array then it returns 3. It will also give the rank whether it is 1-D, 2-D and many more. - shape attribute returns the number of rows and the number of columns present inside an array. - size attribute gives the size of the entire block. - flatten attribute convert the 2-dimensional array into a single-dimensional array. #3 - reshape attribute is used to change the dimensions of an array. We can convert a 1-D array to a 2-D array by using the reshape method. - reshape(r,c) method takes two parameters ie., the number of rows and a number of columns, that you want in an updated array. - reshape attribute also works with a 3-D array. In 3-D, we have multiple 2-D arrays. And a 2-D array contains multiple 1-D arrays. #4 - Matrices can be defined as a two-dimensional array that has multiple rows and columns. - A matrix that has one row and multiple columns is known as a row matrix. - A matrix having one column and multiple rows is known as a column matrix. - Both the row matrix and column matrix is in the form of a single-dimensional array. - A separate format available for a matrix in python. #5 Functions with matrix:- - matix() attribute is used to convert an array into a matrix format. - We can also create a matrix without using an array. It can also be created directly by using the matrix() attribute. matrix('1 2 3 6 ; 4 5 6 7') In this, values are separated by using the space, and rows are separated by using the semicolon. - A diagonal () function can be used to only print the diagonal elements of an array. - min() function will give the minimum value element from an array. - max() function is used to get the maximum value element of an array. - There is a certain number of rules that should be followed in matrix multiplication. Github :- https://github.com/navinreddy20/Python- Python for Beginners :- http://bit.ly/3JOLQhl Java and Spring Framework For beginners with Spring Boot : - http://bit.ly/3LDMj8D Java Tutorial for Beginners (2023) :- http://bit.ly/3yARVbN Editing Monitors : https://amzn.to/2RfKWgL https://amzn.to/2Q665JW https://amzn.to/2OUP21a. Editing Laptop : ASUS ROG Strix - (new version) https://amzn.to/2RhumwO Camera : https://amzn.to/2OR56AV lens : https://amzn.to/2JihtQo Mics https://amzn.to/2RlIe9F https://amzn.to/2yDkx5F Subscribe to our other channel: Navin Reddy : https://www.youtube.com/channel/UCxmkk8bMSOF-UBF43z-pdGQ?sub_confirmation=1 Telusko Hindi : https://www.youtube.com/channel/UCitzw4ROeTVGRRLnCPws-cw?sub_confirmation=1 Donation: PayPal Id : navinreddy20 Patreon : navinreddy20 http://www.telusko.com/contactus
#31 Python Tutorial for Beginners | Working with Matrix in Python
Introduction to Multi-Dimensional Arrays in NumPy
In this video, the instructor introduces multi-dimensional arrays in NumPy and explains how to create and manipulate them.
Creating a Two-Dimensional Array
- A two-dimensional array is created by adding two arrays inside one big array.
- The
dtypeattribute can be used to determine the type of data in the array.
- The
ndimattribute can be used to determine the number of dimensions or rank of the array.
- The
shapeattribute returns a tuple with the number of rows and columns in the array.
Manipulating Multi-Dimensional Arrays
- The
sizeattribute returns the total number of elements in the array.
- The
flatten()function can be used to convert a multi-dimensional array into a one-dimensional array.
- To convert a one-dimensional array into a three-dimensional array, additional values must be added to it first. Then, reshape it using
.reshape()method.
Conclusion
In this video, we learned about creating and manipulating multi-dimensional arrays in NumPy using Python programming language.
Creating 2D and 3D Arrays
In this section, the speaker explains how to create 2D and 3D arrays in Python.
Creating a 2D Array
- To create a 2D array, you need to pass the number of rows and columns as arguments.
- For example, if you want a matrix with three rows and four columns, you would pass
3for the number of rows and4for the number of columns.
- Use the
numpy.array()function to create a 2D array in Python.
Creating a 3D Array
- To create a 3D array, you need to pass three arguments: the number of matrices, the number of rows per matrix, and the number of columns per matrix.
- For example, if you want a big array with two matrices that each have two rows and three columns, you would pass
2for the number of matrices,2for the number of rows per matrix, and3for the number of columns per matrix.
- Use the
numpy.array()function to create a 3D array in Python.
Matrices in Mathematics
In this section, the speaker discusses matrices in mathematics.
What is Matrices?
- A matrix is a two-dimensional array that has multiple rows and multiple columns.
- You can represent one row or one column as an array.
Diagonal Elements
- Diagonal elements are those elements where row index is equal to column index.
- You can extract diagonal elements from any given matrix using numpy.diag() function.
Matrices in Python
In this section, the speaker explains how to use matrices in Python. They cover the concepts of minimum and maximum elements, adding two matrices, and multiplying two matrices.
Using Min and Max Functions with Matrices
- The
minfunction returns the minimum element of a matrix.
- The
maxfunction returns the maximum element of a matrix.
Adding Two Matrices
- To add two matrices, simply add their corresponding elements together.
Multiplying Two Matrices
- Multiplying two matrices is more complex than adding them.
- Watch the speaker's video on how to multiply two matrices for an explanation of the logic behind it.
- In Python, you can use the
*operator to multiply two matrices together automatically.
- Manually multiplying two matrices requires using row and column combinations.
Conclusion
Matrices are powerful tools in programming that allow for complex calculations. By understanding how to use them in Python, you can simplify your code and perform advanced operations with ease.