In this comprehensive course, you will learn Python programming from scratch for mechanical engineering. Starting with the basics like variables, operators, and the interactive shell, you will quickly progress to powerful data and computation libraries. You'll master numpy for numerical computations and matrix operations, pandas for handling CSV and Excel data and mapplot lib to visualize your engineering analysis. This course is even good if you already know Python. >> Hello everyone, welcome to the course on Python for mechanical engineers and robotics using chat GPT. I am Chintan Morsia your instructor and I will be guiding you through this course using different modules to understand the use of Python in the field of mechanical engineering. Python as many of you may already know is a versatile and beginnerfriendly programming language. Today we will dive into why the Python has become an essential tool for modern mechanical engineers and explore its numerous applications in this field. Python is highle interpreted interactive and object-oriented scripting language. Python is designed to be highly readable. It uses English keywords frequently where as other languages use punctuations and it has fewer syntactical constructions than other languages. Why these all are the advantages? We will understand in our further sessions. Python is an open-source and cross-platform programming language. It is available for use under Python software foundation license and it is available on all the major operating system platforms like Linux, Windows and Mac. To facilitate new features and to maintain that readability, the Python enhancement proposal process was developed. This process allows anyone to submit a PEP for a new feature, library or other addition. The design philosophy of Python emphasizes on simplicity, readability and unambiguity. Python is known for its batteries included approach as Python software is distributed with a comprehensive standard library of functions and modules. Python supports imperative structured as well as object-oriented programming methodologies. As we already discussed, Python code style is actually more of a design philosophy and suggest to write a code which is clean, simple, beautiful, explicit and readable. Python was developed by Guidoan Razam in the late '90s and in early '90s at the National Research Institute for Mathematics and Computer Science in Netherlands. Now let us discuss the important features of the Python. Python is evolving every day where now the Python 3.x is receiving regular updates. Python's developer community is focusing on performance improvements making it more efficient while retaining its ease of use. The first feature is the Python is interpreted. Python is processed at runtime by the interpreter. Here you do not need to compile your program before executing it. Python converts the source code to byte code using the interpreter and then executes the byte code using the Python virtual machine which translate it into the machine code instructions for the processors to execute. As we already know computer can only understand the binary language that is the zero and one. So to get it converted into the machine code the Python virtual machine is provided. Python language is interactive as you can actually sit at a Python prompt and interact with the interpreter directly to write your programs. Python is object-oriented that means Python supports object-oriented style or technique of programming that encapsulates code within objects. The meaning of object-oriented is you may see any physical entity it may be a living or non-living nearer to your environment. You can convert each entity into the different variables, methods and the functions using this concept of object- oriented language. How this object- oriented language is useful that again we will understand in our further sessions. Python is a greatest language for the beginner level programmers and supports the development of wide range of applications from simple text processing to browsers to the games. Python is being heavily used for machine learning, artificial intelligence and data science. So for sure its future remains bright. Its role in these rapidly growing fields ensures that Python will stay relevant for further years. Python is also increasingly becoming the first programming language taught in the schools and universities worldwide. So it solidifies its place in the tech landscape. So I hope you got the idea that how important to understand the Python language is not only with the perspective of mechanical engineering but with the perspective of the current development. We must need to have the knowledge of any of the best used programming language in the current market era. In our next session we will also understand the significance of Python in the mechanical engineering field. Looking forward to see you all in our further session. Till then thank you. Hello everyone. In this session, we will understand the significance of Python in mechanical engineering. Computer programming may not be our main focus as mechanical engineers, but in today's digital world, these skills are crucial. Learning a user-friendly language like Python can pay a huge dividends. Since this language pre-quipped with all the scientific and mathematical tools we need, it's easy to expand Python scripting into many use cases. As your command over it grows, Python can open doors to faster and more optimized workflow. It can simulate a huge amount of data and most crucially, it can automate boring and tedious tasks so that they are finished in a matter of seconds. Using Python, you can use built-in functions to run numerical analysis faster and easier than ever before. You may make use of many packages that come with Python like numpy, pandas, scypi, mplot lib and many more to make your work faster based on your requirements. With just a little bit of setup in the beginning, you can use python to write a program that will execute any calculations you need in an instant. Considering so many different uses of Python in the mechanical engineering, there are top four uses of Python in mechanical engineering. Let us understand the use of Python in data analysis and the simulation field. The most widely used Python application is numerical analysis. It would take a long time to answer problems analytically when linear equations and ordinary differential equation and partial differential equations are inward. In mechanical engineering, boundary conditions are frequently present making numerical analysis problems twice as difficult to solve. Assume you are attempting to determine the pressure difference across a pipe with a liquid running through it. Not only will solving the problem take an eternity, but obtaining correct data and plotting the difference in a graph will be nearly impossible. You may solve such problems in a couple of seconds with programming languages and get graphical simulation at the same time. Learning, numerical analysis and coding gives up a world of possibilities in industries such as manufacturing, automotive, energy, and even software engineering like thermal engineers. Mechanical or thermal engineers are employed by software businesses such as Google and Facebook to ensure the efficient and safe thermal management of their database and cluster systems. These engineers build scripts in programming languages like Python using NumPy and Pandas library and then import them into the CFD software to evaluate a variety of ideas. So you may think of the possibilities of using Python in your field. It is having a vast variety of uses but you need to be have the open mind to understand all these different possibilities. Secondly, let us understand the use of Python in thermodynamics. Python can be used to address problems with classical thermodynamics. You may develop a code to solve your problem and save time. Whether it includes chemical kinetics or fluid dynamics, industries in the real world are unconcerned about how you solve problems or finish jobs. You may either spend 60% of your time addressing the mathematical or thermodynamic problems and rushing through the remaining 40% of the assignment or you can spend 20% of your time tackling these problems in Python and focusing on the genuine issues at the end. Your efficiency is the sole aspect of your result that matters. Python has a large library and a straightforward syntax that makes it simple to address difficult issues. Third major application is the computational fluid dynamics. Python has a wide range of applications in the field of computational fluid dynamics. You will need to develop your scripts in programming languages like MATLAB or Python to simulate difficulties with the CFD softwares. You may write scripts for pre-processing simulations and post-processing in CFD. These efficiently handles the complex fluid dynamics problems. Also, you may also integrate the Python libraries like Numpai and Scypi with the CFD software to streamline your workflows. Fourth major use of Python is in control system and in robotics. Control systems are essential in mechanical engineering for designing automated machines, robotics and processes. They help ensure that a system behaves in a predictable and desired manner by regulating its inputs and outputs. Python with its robust libraries like control and metplot lib simplifies the analysis, design and simulation of control systems making it accessible even to those with minimal programming experience. In conclusion, Python is revolutionizing the field of mechanical engineering. Its versatility, ease of use, and the powerful libraries make it an indispensable tool for addressing both routine and complex engineering problems. Whether you are a student exploring new possibilities or a seasoned professional looking to enhance efficiency, Python has something to offer you. So, we may say that Python is a gamecher for mechanical engineers. Thank you for joining me today and I encourage you to start integrating Python into your engineering workflow. You will be amazed by what you can achieve. Hello everyone. In this session, you will understand how to set up a Python development environment to run a Python program in your computer. For those who prefer to install Python on your computer, this guide will walk you through the installation process on Windows. To install Python on your Windows, first go to the Google Chrome. Here you need to go to the Visual Studio Code website. For that, type Visual Studio Code download. In the first link, you will find the option Visual Studio Code link. So, select that link. Here you will see the setup is available for the Windows, for different Linux operating systems and for the Mac. So for your required system you may download any setup. Here we will download the Windows setup. So go to Windows and select it. Now Chrome will automatically start downloading the VS code. Once the downloads complete you will find it in the download section and here you will find the VS Code setup. Now run this installer and here just you need to follow the installation process. So first you need to select the agreement. Select next. Here keep these two options selected. Register code as an editor and add to path. Select next and click on install. So it will take some time based on your computer system and the VS code gets installed into your system. Once the installation completes you will see this screen. Currently, we do not want to launch the Visual Studio Code. So, unselect this and click on finish. Next, we need to download the Python installer. So, to download the Python installer, go to the Python official website. So, for that, go to the search bar and now type Python download. Here in the first link, you will see the official Python website. Select this link. Once the link is open, you will see that the website automatically detects your operating system and gives you the right installer. So here it is already mentioned download the latest version for Windows. At the time I am downloading this software. The current version is the Python 3.13.0. There might be a possibility the version might differ based on your timing. Select download Python and it gets downloaded and you will see it into the download history. Now run the installer. Depending on your security settings, you might be prompted to allow the access. Simply allow it and go to proceed. Once you have run the installer, you will come across this screen. On the screen, you will see two options, install now and customize installation. We suggest you to skip all customization steps and simply click install now. Before you click on the install now, you need to check on add python.exe exe to path as it ensures Python is added to our systems path variable which is recommended and you may also click on use admin privileges when installing python.exe exe. Click install now as it will include all the necessary files needed later. Selecting these options make it easier to run a Python program from the command prompt directly without specifying the full path of the Python executable. Setup progress may take time based on your computer system. Once the setup was successful, you will see this screen and click on close. After the installation is complete, you can verify whether the Python is installed by using some of the commands. So for that first you need to go to the command prompt. So for that click on Windows button and type command prompt and open this application. Now to verify the Python version you need to type python space dash dash version and hit enter. So here you will see the python number 3.13.0. Keep in mind that the version number might differ from the one above depending on your installed version. So with this you are all set to run Python program on your device. In our next video we will start with running your first Python program. I hope you are excited to run your first Python program. So stay connected in the next video and we will start our journey with the Python programming. Hello everyone. Now we are at the point where you can run your first Python program. So to run your first program first open VS code here click on the file in the top menu and then select a new file. So go to file select a new file. Here you will be prompted to select the file type or to enter the file name. So let us enter the file name first program. Here you need to keep in mind that you need to save this file with py extension. This is the Python file extension. So let us keep it py. Hit enter. Once you hit enter, you will be prompted to save the file. You need to select the folder where you want to save your file. After selecting this folder, go to this file name here. File name will appear that is the first program and provide the extension py and select create file. Now once you save this file in a 99%age cases you will see the popup asking do you want to install the recommended Python extension from the Microsoft for the Python language and it is recommended that you select install. Once you select install the extension will appear and it will start installing extension of Python in your visual studio code. You need to wait till Python gets installed in your VS code system. Once Python is installed, you will see that it will appear that the system is installed. Now there might be a possibility you have not received that pop-up. So no need to worry again. You can install this Python by going to the extension section. So for that in the VS code you need to click on the extension on the left side bar. So here you will find the option extensions. Click on extensions. Once you click on extensions, you will find the search option and here in this search option you need to type Python. You will find so many different Python extensions. But from that you need to select Python extension by Microsoft and click on install. So once you click on this again you will find the same window and you need to select on the install. Once this extension is installed we are good to go with our first program. So now click on close of this window. Again let us hide this extension. And now the file is created with the name first_program. py. Now you need to write the code as mentioned over here keeping in mind the capital and smaller cases also because this language is also case sensitive. Now write the code in this file as I'm mentioning. First write print within round bracket and within double quote type welcome to Python learning course. So here we have wrote the first file related to the Python. Now to run this file you need to click on the run button on the top right side of your screen. So at this top right side you will find the run button and here it is mentioned run Python file. So click on it. So at the bottom terminal window will open and here you will see the output welcome to Python learning screen. Using this print option we have printed whatever output we are requiring on the screen. So I hope you are excited after running this first Python program and you are happy to learn more about this Python programming language and how we can create a more complex problems and we can solve these more complex problem using this Python language. In our next video onwards we will learn about the Python interactive cell and running different Python scripts. So looking forward to see you all in our further videos. Till then thank you. Hello everyone. Welcome to the next session on Python interactive cell and its scripts. The Python interactive cell and the script running capabilities form the foundation of working with Python. These tools allow engineers and programmers to quickly execute Python commands, debug code, and run complex programs. Let's explore how to use the interactive cell, create a Python scripts, and execute them effectively. The Python interactive cell is also known as the ripple that is the read, evaluate, print and loop. It is a command line environment that lets you execute Python commands one at a time and see results immediately. So some of the features of this interactive shell are it has instant feedback. That means you can execute commands and view the results instantly. It is also useful for experimentation. So mostly it is ideal for testing small pieces of code or learning Python syntax and it is easily accessible as it comes with pre-installed with Python. So it requires no additional setup to launch the interactive cell. In Windows you need to go to the command prompt or in Mac you need to go to the terminal. So for the case of Windows first open the command prompt. After opening the command prompt type python in Windows. If you are having the Mac then you need to type Python 3 in the terminal and then hit enter. Once you hit the Python you will see the prompt like this and now you are present in the Python interactive cell. So here you can try simple commands including the arithmetic operations or maybe the variable assignments and many more. Let us say we want to perform the arithmetic operations. So type 2 + 3 hit enter and here you will get the output five. Suppose I want to create a variables. That means I want to assign values to the variable and then want to perform mathematical operations. So let us say I want to assign x= 10. Hit enter y = 5. And now I want to print the multiplication of x and y. So we can write x into y and hit enter. So again you will get the output to be 50. So as you can see you can perform very simple operations. You can understand syntax using this Python interactive cell. Here I will be giving you some basic functionalities to make you aware of the Python use. But we will understand each functionality in detail in our further sessions. So let us say I want to assign a name and name equal to I want to type Gho. So I will write within double quote Gaz and double quote over. Now hit enter. Now suppose I want to convert these name into the uppercase letter. So again this functionality is available inbuilt in the Python. So for that you need to write name dot we want to convert it into the uppercase. So inbuilt functionality available is you need to type upper and then round brackets and hit enter. So now you will get the output in capital letters. Let us say I am having the list of numbers and I want to find the sum of that numbers. So for that I may write like these nums equal to within square bracket I will provide the values. So values being the 1 2 3 4 and five hit enter. Now I want to find the summation of these values. So again inbuilt functionality available is I will type sum and within bracket I will pass variable nums and hit enter. So here you will see the output to be 15. So as you can see you can perform very basic operations in these interactive cell and you can understand the different concepts or the syntax in interactive cell very easily. The major limitation of this interactive cell is it is great for quick task but it's not suitable for large programs or saving work. For such cases you need to use the Python script. Python script is simply a text file containing a Python code and saved with the py extension and we have already created the Python script in our previous video in which we have ran our first program. So to create the Python script this Python interactive cell is not useful and we need to go to the visual studio code. So to exit from this command prompt or the Python interactive cell you can type exit and hit enter. And to close the command prompt you can directly click on this close button. Now open the Visual Studio Code. Once the VS code is open again go to file select a new file and suppose we want to create a Python script to find the area of rectangle. So provide the name of file to be area py. Hit enter. Select the file location. Again provide the file name to be the area py and select create file. It will create a new file and new window will open with the name area py. Now as we already know the area of the rectangle is length into width. So to find the area we need to provide the length and width and then we need to perform the multiplication operation. So let us define the variable length equal to 5 width equal to 10. We will store the answer into the variable area. So area equal to length into width hit enter. Now to get the output on the screen we need to use the command print within round bracket. Let us type the area of rectangle is then after double quote comma and we will provide the our variable that is the area. So it will print first area of rectangle is and the value of area. We will understand how to use this print function in our further videos. Now to run the program go to this run button and click on it. So it will open the terminal window and here you will see the output. The area of rectangle is 50. Now so this file is saved and you can change the value of length and width and accordingly every time you will get your output. So these script are useful where we want to store our programs and want to run these again and again based on requirement. So understanding the interactive sale and Python script lays the groundwork for efficient Python programming. The sale is perfect for quick experiments while scripts are better suited for reusable and complex projects. With these tools, you can quickly prototype ideas and scale them into a full-fledged applications. I hope you got the idea how to make use of these Python interactive cell and the Python scripts. Now from our next video onwards we will start understanding basic Python syntax. So looking forward to see you all in our next video. Till then thank you. Hello everyone. In this session we will understand how to provide commands in Python programming. Comments in Python are lines of text in your code that are ignored by the Python inter. They are used to explain the purpose of the code, clarify complex logic and make the program easier to understand for others and yourself also. So this video explains the different types of commands in Python, their use and best practices for writing effective commands. There are two types of commands in Python. Single line commands and the multi-line commands. To understand that, let us go to the Visual Studio Code. Now, as we have already discussed, you can create a folder and save your file in that specific folder with the extension py. Now once you are opened in that folder you can directly create a new file by going to these left hand side bar of the VS code. Click on this explorer and here you will see list of programs that you have created. So in this section programs is mentioned that is folder name in my case. In your case folder name may be different. To the right hand side of it you will find the different options to create a new file new folder. So here we want to create a new file. So click on it and provide the file name with the py extension. Let us give file name to be commands py. Now you can hide this explorer by again clicking on it. First we will understand the single line commands. The single line command start with the hashtag symbol. So to provide the command first you need to type hashtag and now you can write any of the command that you want to provide to your program. Let us write use of comments in Python. Again hit enter. Now suppose I am considering x= 10 and I want to print x. So type print x and run the program. So here in the terminal you will find that the output is 10 but the statement that we have written using the hash symbol is not printed or not executed in the program. So this comment is used on a specific line to explain a piece of code but it is not executed by the interpreter. So how this comment is useful? Let us say we have already mentioned x= 10. So now we want to explain to someone that what is the meaning of x= to 10. So we may use these hash symbol and now type it is the assignment of value 10 to the variable x. So we can write assigning value 10 to the variable x. So this comment explain what is the meaning of x= to n. Same way next statement we have written the print x. So if you want to explain someone what is the meaning of print x again we can type hash and the purpose of this print function is it prints output on the terminal or the console. So let us write useful for getting output on console. So I hope that you got the idea what is the use of commands in this Python program. Now second one is the multi-line commands. So as the name suggest we can provide the commands to the multiple line also. The first useful approach is we may use multiple time hashtag symbols to provide the multi-line comments. Let us use the multiple hash symbol. First comment is this is multi-line comment. Suppose this is line one of the command and second one is the line two of the command. So here as you can see we can provide the multiple commands in individual lines by using this a symbol. The Python doesn't have a direct syntax for multi-line commands but you can make use of the ripple quotes as a workaround. As you can see if our comment is of more than 10 to 15 lines. So it is somewhat tedious to provide the hashic symbol to each and every individual lines. So for that we may use the concept of triple quotes in the Python to provide the comment. Let us copy above all three lines and again use it for the purpose of triple quotes. Now for the reference you can comment all these lines by using the shortcut also. You can press control + forward slash in the windows and command plus forward slash in your Macs. Suppose we want to uncomment all these three lines. So again press control plus forward slash. Again if you want to provide the multiple commands so you can press command plus forward slash or control +/ in your system. As we want to provide the multi-line commands let us uncomment all these lines. Now to provide the multi-line commands you can use triple quotes symbols. So first provided triple quote at the starting of the command. So here you will see we have provided the triple quotes and within these triple quotes we need to provide our multiple lines. So let us cut these lines from here and paste it in between. So here you can see all these lines are considered as the command by the Python. So this is a multi-line command and it spans across multiple lines useful for the detailed explanations. Here just keep in mind that these triple quoted commands are typically a string lit but are often used as commands when not assigned to a variable. What is the string lit is? We will understand this in detail in our further sessions. So using a single hash symbol you can provide a single line command or using the triple quotes you can provide the multi-line comments. So why to use these commands? So these comments enhance the readability. That means it helps others to understand the purpose of the code. It clarifies the complex logic by breaking down the complicated sections of the code in explanatory comments. It also aids in debugging aid. That means you can temporarily disable parts of the code during debugging and you can specifically select a portion of the code that you want to check. And the last one is the documentation. So you can provide the details about the course functionality, inputs, outputs and the limitations. I hope you got the idea how to use the Python commands and what is the importance of Python commands in Python. Hello everyone. In this module, we will understand different Python variables. A variable is a named reference to a memory location that stores data. The values stored in a variable can change during the program execution. to understand the Python variables. Again let us go to DBS code for the reference you can create a new file and in that file you can practice with this video together. Let us consider first example. If I am writing X= 10. So here X is a variable storing the value n. There are mainly two features of variable. The first one is the dynamic typing and second one is the mutable in nature. So what is the meaning of dynamic typing? Here as you can see we have written x = 10. So here x represents the integer type. We may also write like name equal to python. So here you can see by default interpreter understand that it is a string. Same way if I'm writing z= to4. So here interpreter will understand it as dot. So here no need to declare the data type explicitly. Python determines it automatically. Second is the value of the variable can be reassigned based on the requirement. So here first the value of x is equal to 10. So if we are printing value of x it gets printed as the if you want to change its value we can also write x= to 20. So now the value of x is 20. If we print x again python will consider its value as 20. Let us run program. So here you will see that the first value of x is 10 and secondly value is 20. So I hope you got the idea how to create different variables. There are certain rules are there for naming the variables. So let us understand the rules for naming variables. First rule is we must start with letter or underscore. So suppose I want to provide a variable name the valid variable equal to 10. So this is the valid variable name as it is starting with the letter four. You can also start with the underscore that is underscore private equal to five. So again this name is valid. Second important rule is we cannot start with a digit. So suppose the name is one variable equal to 10. So as you can see here Python highlights it with the red color that means this name is not valid. So keep in mind that we cannot start the variable name with digit. Let us comment it to avoid the error. Third important rule is it can contain letters, digits and underscore and its combination. Means if I am keeping variables_1 equal to five. So again this name is val. Fourth rule is Python variable name is case sensitive. That means if I am keeping age equal to 25 and second capital A with the same name age equal to 30. So these both variable names are different. So again this point is important to note the variable names are case sensitive in the case of Python. And the last important rule is we cannot use reserved keywords. Now what is the meaning of reserved keywords that we will understand in our further sessions also but you can think like that the keywords like if else for which are inbuilt available in the Python these same names we cannot assign as a variable names. So I hope you got the idea how to define the variable name in Python. In our next video we will understand how to assign the values to the variable in the different manners. Hello everyone. In this video, we will continue our discussion on Python variables and we will understand how to assign values to variables in a different manners. To understand this, let us again go to the VS code. Here the first approach is single assignment that we have already discussed. You can assign a value to the variable using the equal to operator means x equal to 10. So here value 10 is assigned to the variable x and it is the single value that's why it is known as the single assignment. Second approach is the multiple assignment. Here you can assign values to multiple variables in one line. That means if I want to assign value a= 1, b = 2, c= 3. So here you can see to assign values to these variables we need to write the three different lines. In place of that you can use the multiple assignment like this you can write a comma b comma c equal to 1a 2a 3. So it is having the same meaning as the abolines that is a= 1 b= 2 and c= 3. Now the next approach is you can also assign a single value to multiple variables. So suppose I want to assign value 100 to variable x y and z. So we can write x = y = z = 100. So here you can use these different approach of the assignment based on your requirement. Now as you have observed till now python variables can hold different data types such as numeric data types, string data types, boolean data types and collection data types. So let us understand these data types in detail. So from these variable data types, the first one is numeric types. Numeric type data types means it can hold the numeric values and this data type being int, float and complex. So these are the inbuilt reserved keywords to represent the integer, float and complex values. Suppose I want to store integer value is 10. So num equal to 10. Here Python consider it as the integer data. If I'm storing pi = 3.14 as this one is being the value in point. So Python consider it as plot. Suppose we want to store the complex number. So let us give the variable name as complex number equal to if I'm storing 2 + 3 J. So here Python consider it as the complex number. So these are the three different data types available in the Python for the numeric values. Now the second data type is string. So string is nothing but the sequence of characters enclosed in a quotes. It means if we want to store the name Python. So we need to write a name equal to within double quotes Python. So whatever the sequence of characters we want to store, we need to compulsory provide these values between the double quotes. It is the compulsory syntax to store this string type data. Third type is the boolean. So boolean simply represents the true or false. So suppose in any of my program if I want to represent switch is on yes or no. So for that we can store it into the boolean data type indicating true or false. So suppose if I'm storing it under the variable name is own equal to if I want to say yes then we will store it as the true. You may also store it as the false based on your need. Fourth important data type is the collection that is the collection types and it includes list, tpple, dictionary and set. If we want to store more than one values in a single variable, then these different data types are useful. Suppose I want to store numbers such as 1 2 3 in a one variable only. So let us say the variable is numbers equal to I want to store the values 1 2 and 3. So to store it in the format of list you need to first provide the square brackets within that provide the multiple values using the comma separation. So if I am entering 1 2 and three here these three values are stored in the variable numbers and square bracket represent it as the list. Now suppose I want to store the coordinates in the double type. So for that I need to use the round brackets and within round brackets you can provide the required values. So suppose I am storing the coordinate being the one. So round brackets consider it as the t. Next important type is the set and set is useful to store the unique values means if we do not want any repetition in the values. So at that time this set type is useful. So set always represent the unique values. So let us keep the variable name as unique values equal to to represent the set we need to use the curly brackets and within which again we will provide our values. So curly bracket represent the set. The last type is the dictionary. So dictionary is the important type in which the data is available in the format of key and value. That means with one specific entity if we want to represent its specific value then this dictionary is useful. So let us take the example if we want to store multiple data of a person in a single variable then this dictionary is useful. So let us say I want to store the name of a person and age of a person in a single variable. So in such case dictionary is useful. So let us take the variable name is person. To represent the dictionary again we need to provide the curly brackets within this. You can provide multiple data types based on your requirement using the comma separation. So let us say I want to store the name. So I will provide the variable name being the name. Then we'll separate it with the symbol colon. Now we need to provide the name. Which name we want to store? Suppose I want to store Python. So I will type Python. So here this Python name is assigned to the name. Second I want to provide the age. So I will provide the comma to separate the second data. Now I want to store it into the variable age. So again take age. Next we need to store its value. So again separate it with a colon and we'll provide the value to be 30. So here you can see Python is stored in the name and value 30 is stored in the age. So this type of data type is known as the dictionary. So these are the four different data types that are the way more useful in your different programs based on your requirements. You may practice the separately for each different data types based on your requirement. And here you can see that we do not need to specify the specific data type based on the value. Python automatically detects which data type we have provided. So we need to be careful with the syntax of different data types as Python detects the data type based on that specific syntax. I hope you got the idea about different variables, how to provide the name to the variables and what are the different rules to provide the variable names. Looking forward to see you all in our further sessions. Till then, thank you. Hello everyone. In this video, we will understand what is the meaning of Python literal. Literal are constant values that are directly written in the code. They represent fixed data and are assigned to variables or used in expressions. To understand this, let us go to this visual code. Here you can see we have stored multiple values in the variables in our previous session. So here you can see again x= to y= z equal to 100. So this value 100 is known as the lit. There are different types of lit are there. Let us say the first is the numeric lit. Here num equal to 10. So this 10 represent the whole number and it is the integer lit. I equal to 3.14. So it is the numbers with decimal. So it is known as the floating point lit or the float lit. In the complex number value stored is 2 + 3 J. So these number 2 + 3 J is known as the complex lit which represents the real and imaginary part. String lit represent the text and are enclosed in single, double or triple quotes. Now what is the meaning of that? Let us again understand with the example. As you can see here, we have stored the name equal to P. We have stored it with the double quotes. Same way you can store string literal using the single or triple quotes also. So suppose I want to store hello in a single line. So I will type single line being the variable name and within the single quote hello. So again this value hello is stored in the variable single line. But suppose I want to store string data in multiple lines then we need to use the triple quotes. So suppose I want to store in multi-line. So keep the name of variable to be the multi-line equal to. We will use the triple quotes provide triple quotes. Hit enter. And now between these triple quotes you can type any of your required line. So let us type this is multi-line string. So here you can see we have stored the value in multiple lines using a single variable. So these are the three different approach to represent the text using the string lit and that are enclosed in single, double or triple quotes. Next is the boolean lit. Here you can represent true or false. So these value true or false represents the boolean lit. Next is the collection lit. It is used for creating list, tpples, dictionary and sets. So again you can see here the value stored between the square bracket, round brackets and the curly brackets. These all are known as the collection lit. There is one more special lit is there and it is the none lit which represents the absence of value. So suppose if I am storing data equal to none. So here none represents that there is absence of value in the variable data. So it is known as the special letter. I hope you got the idea what is the meaning of literal in the Python context. The variables in Python are dynamic in nature. It means if I am storing the value a equal to 10. So the current data type of variable a is integer. But next if I am storing a equal to within double quote hello. So now the data type of variable a is being string. So this is the beauty of using Python language and the easiness of using this Python language. So this understanding of variables and literal is crucial for building efficient Python programs. Variables act as a flexible container while literal provide a fixed data values. With this knowledge you can efficiently store, manipulate or retrieve data in your further Python programs. Hello everyone. In this video we will start discussion regarding to the Python type conversion. Type conversion in Python refers to the process of converting a value from one data type to another. It plays a crucial role in Python programming by ensuring compatibility between different data types during operations or function calls. So this video provides a comprehensive explanation of type conversion, its types, methods and its some of the practical examples. So why type conversion is required? Type conversion is required to ensure compatibility during operations between different data types. It is used to manipulate or format data for specific requirements and it is also used to handle user inputs which is often treated as a string and we can convert these into any other required data type using the concept of type conversion. So to understand this let us go to this VS code create a new file for the practice purpose. Let us take the example x= 10. So here we know that it is of data type integer. Now suppose I want to convert it into the float data type. So we will write another variable y equal to the method is first type required data type. So our required data type is float. Now then after provide the round brackets and within round bracket you need to provide the variable or the value which you want to convert. So let us type x. So here with this syntax variable x is converted to float. So it is called the type conversion. Let us print the y and check the value of y. Run the program. So here you can see that in the terminal we are getting the output 10.0. So this decimal value represents the integer is converted to the float. Again let us take some of the examples. Suppose the value of a is 20. So this value is available in the string data type and we want to convert this string into the integer. So let us take variable B equal to first type the data type that is int and within bracket we will pass the value A. So here string A will be converted to the integer B. So I hope you got the idea. This type conversion is used to manage the different data types based on the operations. Python supports two types of type conversion. First one is the implicit type conversion. Let us mention here implicit type conversion. Implicit type conversion means Python automatically converts one data type to another. No other instruction is required from the programmer. So typically it occurs in operations involving different data types. So let us say if I'm considering x equal to 10. So here you can see that the default data type provided to this 10 will be the integer. Next if I am writing y equal to 3.5. So here the data type of the y will be float. Now let us try to sum these. So result equal to x + y. So here you can see that x is the integer data type. Y is the float data type. Whenever we are adding these two integer plus float will be automatically converted to the float. So the value or the data type float will be assigned to this result variable. Let us print the result. So here when we run the program you can see that the output is 13.5. It represents that the data type assigned to the result is the float data types. Python has automatically assigned the required data type to our variable and it is due to the implicit type casting. To check the type of variable you can make use of the function type and within bracket pass the variable that is x. We want to print the output of data type on the screen. So again we will write these function within the print function. So print type x. Now run the program. So here you can see that the class is int. That means the data type provided to the x variable is integer. Same way if you want to check the data type of result. So again type print within bracket. Type within bracket result. Again run the program. And here you will see that the type provided is the floppy. So I hope you got the idea. The implicit type conversion means the automatic type conversion that Python performs automatically. Second one is the explicit type casting. Now it is also called the type casting and it is performed manually using the built-in functions and it allows the programmer to control how the data is converted. There are some common functions are available for explicit conversion. So first let us refer to that common conversions. So here you can see that in the table first function is the int and it converts the data type to the integer means in the example as you can see if I want to convert 1 2 3 into the integer then I need to type int and within bracket I will provide the variable or the value which I want to convert. So similarly you will find different functions for the explicit conversions. So to remember that you can simply keep in mind that you need to have the exact idea about the name of data type. Let us say int, float, string, list, tuple, set and bool. And based on that name only these functions are created. So you may be able to easily remember these functions based on your need. Let us understand this explicit conversion with the examples. So again go to this VS code. Now suppose I am storing the value pi equal to 3.4. Now I want to convert this float variable into the string variable that means I want to change the data type. So for that we need to use the concept of explicit type casting. Suppose I want to store it into the Z variable. So Z equal to now to convert it into the string we will type first str inbuilt function. Then within round bracket we will provide our variable that is the pi. So now here this value pi will be converted to the string. Let us print zed and run the program. So here you can see that at the bottom the value printed is the 3.14 but it is of type string. To verify that again type print type and within bracket z again run the program and here in the output you can see that the class is string means now our float value is converted to the string. Let us again take another example. Suppose the value a1 equal to zero. Now I want to convert this zero into the boolean variable and the boolean data type that's why let us take variable B1 equal to convert it into the boolean variable we will type bool within bracket value that is the A1. Now to print it let us type print B1 and to print its type also we will type print type and B1 and run the program. So here you can see that the zero refers to the false value and the data type is the boolean. So I hope you got the idea how this type casting is useful and there are two types of type casting that is the explicit and the implicit type casting. So the important points to remembers are first is type conversion is the conversion of an object from one data type to another data type. Implicit type casting conversion is automatically performed by the Python interpreter. Python avoids the loss of data in implicit type casting. Explicit type casting is also called only type casting and the data types of objects are converted using predefined functions by the user. In type casting loss of data may also occur as we enforce the object to specific data type. So the meaning of that is suppose as you can see we have provided the variable pi that is equal to 3.14. I want to convert it into the integer. So let us type C1 equal to int 5. So here you can see that we are trying to convert the decimal value into the integer value. That means in place of 3.14 we will get only output three. So this 14 is nothing but the loss of data. So there may be a chances that due to the explicit type casting if we don't know exact requirement of our program then there might be a possibility that we may lose some of the important data. So let us check the output again. Type a print and see what run the program. So here you can see that the output is three. That means the other decimal values are lost due to this type casting. I hope this type casting concept is helpful to you and you are getting the exact important details that are needed for our further programs. Looking forward to see you all in our further sessions. Till then thank you. Hello everyone. In this video, we will understand use of basic input and output in Python. Basic input and output operations in Python allow interaction between the program and the user. Input lets the program receive data from the user while output displays the data to the user. These operations form the backbone of creating interactive and dynamic Python applications. This video explores how to use output functions effectively including formatting techniques and practical examples. Python uses the print function to display output to the user. Now the syntax of print is as you can see on the screen. First you need to tap the print within round bracket. You can provide three different values. First is object. Object refers to the one or more items to be printed on the screen. Second is the separator and for that you need to type se equal to. Then within single quote or double quote you can insert the object with which you want to separate the multiple objects and the default value provided is a space. Third is the end. It defines how the final data is printed at the end of your statement based on the tool or the value provided over here. So here the string is appended after the last object and the default value is the new line. That means once you print the data then after new line will be created and the next data will be printed on the new line. Now to understand this print function in detail let us go to VS code. You may have already used print function in our previous programs also but now here we will understand the different use and the different methodology how we can use this print function. So the first method is you can simply type print and within which within double quote whatever data you want to print you can just provide in between this double quote. So here currently we have written print within double quote python world. So once we run this program we will get the output python word you can see on the screen. Second advantage is you can print multiple objects also. Let us take the second example and comment this data. So here you can see that we have printed four different entities. First name, John, comma, age, comma, 30. So this comma separator combines all these four different words into a one single line. So again run the program and here you see that the output is name, John and age 30. And between each object you can see that the default space is provided. Third is you can make use of the custom separator. So let us have a look at the third example. Here you can see that we have printed three different words. Python comma is comma 1. Here we have used the separator. So to use the separator we need to type se equal to then within single or double quote you can provide your separator. We want to separate each word with the dash. So here we have provided dash. run the program and see the output. So at the bottom you can see that the python dash is -1. So each word in place of a space separated by the dash. Other than these you can also provide different escape characters based on your need. So what are the escape characters? Escape characters are special characters used to format the output. So here the default syntax are backward slash n represents new line backward/ t represents the tab two backward slash represents the back slash single backward slash with a single quote and the double quote represents the use of single and double quote. So these are the standard syntax you may utilize based on your format. So let us again go back to VS code. Now consider the same example. Here the data printed is Python is one but here I want to separate it with the tab means the space similar to the tab will be provided between each word. So type within separator backward/ e again run the program. So here you can see that the space provided python is one. Same way suppose I want to print in the new line. So you can use the separator / n. So change the value to backward SL and run the program. Here at the bottom you can see the output Python is one. So each word is separated by a new line. Fourth use is you can make use of the custom end characters also. So for that consider the next example. Here you can see that first we have printed hello and then we have provided the end character to be the comma. That means after end of this print statement the comma will be provided. The next statement is world. So now between these two end point used is the comma. Run the program. So at the bottom you can again see the output. Hello. Comma is provided due to the end and the word. Now again here you can provide any of the escape characters based on your need or you may change any required formatting data based on your requirement. Next we will understand how we can format the string properly for the proper visualization using some of the functionalities. So the first use is using the f string function. Consider the example for the same. So say the name is stored as John and the age is provided 25. Now I want to print John is 25 years old. But I do not want to provide the fixed value but I want to print based on the variable values because there might be a possibility the name and the age may change based on the user input or the variable values. So how we can use so first you need to type the print then to use the fing first type f then now within double quote you need to use your required string and the curly brackets. So suppose I want to print first name. Now these refers to the variable. So to refer the variable we will write that variable within curly bracket. So within curly bracket provided the variable name. Next string that is is now I want to provide the age. So again it is variable. So we will type within the curly brackets. So within curly bracket age is provided. And the next statement is years old. That means whatever name we are providing and the whatever age we are providing accordingly this printing statement will change. So again run the program. So here you will see the output John is 25 years old. Now there may be a possibility in place of John we are providing the name to be Jane and the age to be 35. So now printing statement will remain same but based on the variable name and age will change automatically based on the inputs. So again run the program and here you can see the output JN is 35 years old. So this is the beauty of using fstring functionality to provide proper formatting to your output. Second method is using format method. So consider its example again. Here you can see that first variable name one is Bob. Second variable name two is Jen. Now there is another possibility that you do not want to provide the variable's name in between but first you provide the syntax for the same and then at the end you want to define the variable names. Let us take the example. Suppose I want to print hello Bob I am Jen. So as you can see the Bob is stored in the name one and the Jane is stored in the name two. So we will write print within double quotes hello. We want to provide the name that is Bob. But it is in this variable. So we will provide only curly brackets. Comma I am Jen. Again Jen is stored in the name two variable. So we will only provide the curly bracket. We will complete our string with the double quotes. Now in place of curly brackets, we need to provide which value will go in curly bracket. But we need to provide these values in the same sequence as the curly brackets provided. Means as I want to type first Bob in the first curly bracket. So we will type dot format and within round bracket we will provide the number of variables based on the curly brackets available. So first we want to provide the Bob. So here we will write dot format name 1 comma for the second curly bracket we will provide the name two. So here in the first curly bracket Bob will be passed and in the second curly bracket name two that is the gen will be passed. So again run the program. So you can see that the output is hello Bob I am Jen. But now suppose if you have changed dot format first you have provided name two and then you have provided name one. So now in the first curly bracket name two will go and in the second curly bracket name one will go. So now run the program. So you can see the output hello gen. So we need to keep in mind in which curly bracket we need to provide which variable. So accordingly we need to manage the sequence. So these are the different methods available to format your outputs. Now same way as we have understood there are different escape characters are available between the strings. You can also use different escape characters. Suppose I want to print Python world. But here I want to separate Python and world with the new line. So for that just we will provide escape character over here. Backward sl. So this backward/n will provide the new line between these two words. So run the program. So at the bottom you can say that the python and world both are separated by the new line. If you want to provide the space as much as tab then type / t again run the program. So now here you can see that the space is provided that much of tab. So I hope you got the idea how to use this output functionality using the print function in Python programming. Hello everyone in this video we will understand Python input. So Python uses the input function to take input from the user. To understand the syntax of input function go to the VS code. So the syntax of the Python input is first you need to type the input and then within bracket you will provide the prompt. So what is the meaning of prompt? Prompt is a optional text that is displayed to the user before taking the input. So suppose I am typing enter your name. So that means on the screen user will be displayed that enter your name and after this user will be asked to enter the name on the screen. Now this is the method how we will take the input but where this input will be stored. So this always returns the input as a string. We need to store the answer by default into the string data type. So suppose we want to store it into the variable name. So type name equal to input enter your name. So whatever the entry user will be entering that will be stored into the name variable and then after we want to print let us say if hello and then name of that person. So within curly bracket we will type name. So here we have used the string formatter to print the data. Now run the program. So as you can see on the screen you will be asked to enter your name. Enter your required name. So I'm entering John and hit enter. So here you can see that whatever the entry user has entered that value will be passed into the variable name and this name will be passed into our print function. So we got the output hello John here. Keep in mind that the default data type of the input function is the string. So always the output will be given in the string data type. But it is not always required that we want the string output. There may be a necessity that we want to have some numbers and we want to perform some of the mathematical operations. For this we need to use the concept of type conversion. We already know how to convert the data type from one data type to another data type. Let us take the another input age equal to input and the prompt provided will be enter your age. Now here the data type of the age will be string. To check the data type write print type and variable name age. Now we want to convert these data type string to the integer data type. So for that we will use the explicit type casting. So we will type again we want to store it into the same variable. So age equal to first required data type int and within bracket again age. So this statement will convert string data type to the integer data type. Again let us check the data type. So print type and the variable age. Now run the program. First enter the name. Name being the zone and the age let us say 30 and hit enter. So here you can see that the first data type is string and using the explicit type casting we have converted into the int data type. It is not always necessary to separately type cast the required data type into the different line. You may perform the same task in the same line also. So that means suppose I want to convert these user entered age into the integer data type. We may reduce these lines and directly type age equal to we want to convert it into the int data type and then within round bracket we will provide all the data. So directly it will convert the string data type into the integer data type and it will be stored into the age variable. So this is the methodology to take the single user input but there may be a chances that we want to take multiple inputs also. So for that we need to use split method also. So the method name is split and by default this method splits the data from white space means in your statement whenever you are providing the space from that part it is splitting the data. To understand it, let us take the example. Before that, first comment all the previous data so that we can focus on our next part. Now I want to take the input for two variable XY equal to. We want to take the input. So type input. Here we will specifically say enter two numbers separated by space. And to separate the data after the input method, we will use the method split. So we will type dotsplit and the round brackets. Whenever I am saying the term method that means we need to provide the round brackets at the end of that name. Now we want to print both the values. So type print within round bracket we will use the formatted string. So if first value being the x and the second value being the y. Now run the program. Here we have been asked to provide the two numbers. So first number being the 10 space 20. Once we hit the enter, this 10 and 20 gets separated from the space and 10 value will be stored into the x and 20 value will be stored into the y. So hit enter and here you can see that the first is 10 and the second is 20. Now we already know the default data type of the input method is the string. So suppose if we perform addition on this variable then they will be treated as the string. So let us type x + y and again run the program. Enter the values 10 20. So you will get the output 10 20. As these are the string these two elements get combined but these two are not added as Python is treating it as the different string or the text. Now to perform the summation we need to convert these values into the integer data type. Now to perform the summation let us convert x and y into the integer. So x = intx and y = int y. Now we will print the sum. So let us type print sum is within double quote. We will separate it with the variables with the comma. Now run the program again. Enter the two numbers. Let us type 10 space 20. And now you will get the output sum is 30. So using this input function you may take single value as a input or you can also take multiple values as a input based on your requirement. So this input output functionality is too much helpful to make your programs interactive while you are working with the realtime problems. Now with the completion of all these concepts you are ready to move with the next step of the Python programming that is the operators and the expressions in Python programming. So we will start our discussion onto that topics from our further session onwards. So stay connected with me in the further sessions. Till then thank you. Hello everyone. In this video we will start our discussion regarding Python operators and expressions. Operators and expressions are fundamental components of Python programming. Operators perform operations on variables and values while expressions combine variables, operators and literal to produce result. From this video onwards, we will provide a comprehensive explanation of Python operators, data types and how they are used in expressions with examples. So what is operator? An operator is a symbol or keyword used to perform specific operations on one or more variables or values. There are various types of operators are available. From that we will start our discussion with the first one that is arithmetic operators. You may have already performed these arithmetic operations as a part of mathematics. So these are addition, subtraction, multiplication, division. Now some of the new ones are floor division, modulus and the exponents. So in the first section as you can see here the different symbols that we will be using are provided that are known as the operators. In the first column we will see plus, minus, multiplication. For the division we will use forward slash whereas for the floor division we will use two forward slash. The modulus which will give us the remainder for that we will use the symbol percentage. And to get the power or the exponents we will use the 2 * star symbol to perform that operation. So in the example also you can see addition, subtraction, multiplication and division provides the respective answer. But in division keep in mind that it will provide the float value. The meaning of floor division is that we will only get the quotient value without the decimal. So if we perform 10 / 3 the exact answer will be 3.333. But performing the floor division we will get only the integer number that is 3. Modulus will give us the remainder. So 10 modulo 3 that is equal to 1. that one represents the remainder and the exponent that is 2 start 3 means 2 to 3. So that will give us the output 8. So let us understand all these arithmetic operators in the program. For that go to the VHS code. We have already created a file for your reference. So as you can see we have provided the fixed value num one being the 10 num 2 3. Then we have printed both the numbers first number and the second number. Now first if you want to perform the addition so we have stored it into the addition variable. So num 1 + num 2 that will give us the summation 10 + 3 that will be 13. So here our output will be 13. Next subtraction. So num 1 minus num 2 will give us the output 7. Third multiplication. So num 1 into num2 stored into multiplication variable. And here we will get the output 30. Next is the division. Keep in mind that division will give us the output in float data type. So here 10 / 3 will give us the output 3.333. Next is the floor division. So we will write num 1 2 * forward/ num 2 and it will give us the quotient value in integer. So 10 / 3 it will give us the output three. Next is the modulus or remainder. So for that we will write modulus equal to num 1 modulo num two. So 10 modulo 3 will give us the remainder and the remainder value being the one. Now last arithmetic operator is exponent and for the exponent we will use num 1* star num 2 that means num 1 to num 2. So here we will get 10 to 3. So our output will be 1,000. So I hope you got the idea how these different symbols we need to use to perform some of the arithmetic operations. Now run the program. So here you can see that first number 10 second number three and accordingly we have performed the operation addition, subtraction, multiplication, division, floor division, modulus and the exponents. These arithmetic operations will be helpful to you while performing some of the mathematical operations based on your requirement. Next we will understand the logical operator. So for that again go back to this slide. So these logical operators are used to combine conditional statements. So as you can see in the example we will be using the three different operators first and then or and the not. So these are the inbuilt keyword that we will be using in Python to perform the logical operations. As you can see in the example these and or and not example works based on the conditional statements. As we know the end operator represents that if any of the condition is false then we will get the output false. If both the conditions are true then and then only we will get our output to be true. Second in or operator if any of the condition is true then we will get the output true. If both conditions are false then and then only we will get our output false. And the last one is the note operator. This operator converts our output if it is false then converts it into the true and if our output is true then converts it into the false. And here keep in mind that the logical operators will always provide output in the boolean data type. So again we will go back to VS code to understand these logical operators. As you can see in the program we have provided the fixed values. First is true, second one is the false. We have printed both the values to be condition one, condition two. Here for the reference we have assumed that condition one is true whereas condition two is false. Now in place of true or false in a real example we will be having any specific condition based on that we will get the output. First is the logical and so as you can see we have stored the answer in variable result underscore end and [clears throat] here we have used the operator and so condition one and is the inbuilt keyword and condition two. So in our case condition one is true and condition two is false. So true and false as it is the end operator one of the condition is false that means we will get our output to be the false. So here our output will be false. Second is or operator. So condition one or condition two. So true or false. So one of the condition is true that's why we will get our output to be true. Third one is logical note. And here as you can see first one is not condition one. condition one is true and we have used the not operator that means here our output will be false and in the second condition again not condition two means our output will be true. So these logical operators will be helpful to get the output based on the combination of different conditions as per our requirement. So I hope you got the idea how these logical operators might be helpful to perform some of the mathematical operations or the conditional check to fulfill our requirement. In this video we understood assignment and logical operators in detail. The remaining operators we will understand in our further sessions. Hello everyone. In this video we will continue our discussion on operators and we will continue with the comparison or relational operators. So these operators are used to compare values and return a boolean result. With the use of these operators, we will always get our output in boolean data type. It may be either true or false. On the first column, you will find that there are specific symbols you need to use to use comparison operators. First is equal to, second is not equal to. So you need to use exclamatory mark and then equal to. Remaining four are same as the mathematical operators. So greater than, less than, greater than equal to and less than equal to. So if provided values satisfy the given operator condition then we will get the output true else we will get the output false. You may refer the examples provided here to understand the output. We will go to the VS code to again understand the use of comparison operators. As you can see in the example we have provided the fixed values number 1 15 number two 10. We have printed both the numbers first and second number. Now first operator is the equal to operator. As you can see we have used the operator num one equal equal num two. So here you can see that 15 equal equal 10 and the answer is no. So here we will get the output false. Second operator is not equal to. So here we have written num 1 exclamatory mark equal to num two and 15 is not equal to 10. So yes. So we will get the output true. Next is the greater than operator. So here num one is greater than num two. Yes. So we will get the output true. Fourth is num one less than num two. So the answer is no. So we will get the output false. Now the next one is greater than or equal to. So num 1 is greater than or equal to num two. Yes. Num 1 is greater than num two. So here we will get the output true. And the last one is less than or equal to. So here num 1 is less than num two. The answer is no. So we will get the output false. So as you can see based on the provided values these operator checks if both the values are same or it may be a greater than less than or not equal to. So if we want to perform any checks on the numbers then at that point these comparison operators are useful to get the output. Let us run the program. So in the output you can see that num 1 equal to num two the answer is false. Num not equal to num two answer is true. num one greater than num two again answer is true. So same way you can check the answer as we have discussed accordingly we will get the output. So here output depends purely on the provided values and based on that Python will give the output. Next we will understand the assignment operator. So for that again go back to the slide. These assignment operators are used to assign values to the variables and there are different methodologies to provide the assignment. The first operator is equal to. So it will directly assign the value if we have written x equal to 5. So these five value will be assigned to x. Other than that we can also perform arithmetic operations combining with the assignment operators. So on the first column again you can see we have provided the operators combining with the arithmetic operators. So first plus equal to minus equal to multiply equal to divide equal to floor divide and assign exponent equal to and the modulo equal to. So what is the meaning of this symbol that is provided in the description. So plus equal to refers to that first we will add and then assign the value. So as you can see in the example we have written x += 3. So the meaning of that is x = x + 3. Same way if we have mentioned x -= 2 then the meaning of that is x = x -2. Same way you can understand the meaning of remaining operators. So to understand the output of these operators again let us go back to the VS code in the reference program you can see that first we have provided the fixed value using the assignment operator equal to. So num equal to 10. So this is the initial value. Now again we are using the assignment operator and we have provided num equal to 15. So now the new assigned value to num variable is the 15. Next is num plus equal to 5. So plus equal to 5 means first we will add and then assign the value. So the meaning of num plus equal to 5 is num equal to num + 5. The updated value of the num is 15. So 15 +al 5 we will get the output 20. Next is num minus= 3. So now our output will be 20 - 3. So it is 17. Next is num mult*ly equal to 2. So our output will be here 17 into 2 that means 34. Next is divide and assign. So num divide equal to 4. That means 34ide by 4. So we will get our output 8.5. Next is floor divide and assign. So now floor divide equal to 2. That means 8.5ide by 2. But here we will get our output in the integer value only. So our output will be four. Next is modulus and assign. So num modulo equal to 3 means four modulo 3. So here our remainder will be 1. So our output will be 1. And the last is exponent and assign. So one exponent two. that means 1 to2 and here our output will be 1 to2 that is equal to 1. So again we will get the output 1. So using these assignment operators you can assign fixed value to the variables also or you may perform arithmetic operations with the assignment also. To check the output run the program and at the bottom you can check the output. The initial value is 10. New assigned value is 15. And accordingly the discussed output you can see on the screen. Here you can observe that the divide and assign will provide the output 8.5 and that is the float value. And then after we have performed any operation on this float value and all the values we have received in the float data type. So the answers are not 4 1 and 1 but the answers are in float data type that means 4.0 1.0 0 and 1.0. So while getting the output again we need to keep in mind that the implicit type casting works here based on that we are getting our output in the float data type. Now next we will discuss about the identity operator. These identity operators are used to check if two objects have the same memory location. So the first operator is is operator. The is operator checks if two variable reference the same object in the memory. That means if we have created the two variables X and Y, let us say these two are the objects. So if these two variable are referencing to the same memory location, then we will get the output true. Else we will get the output false. The second is is not operator and it checks if two variable reference the different objects or not. If they refer to the different objects then our output will be true else our output will be false. So you can see over here again these identity operators will give us the output in boolean data type only. That means it will be either true or false. To understand these identity operators again go back to VS code. In the program you can see that we have provided the fixed variable x= 10 y= 10. So these two variables are referring to the value 10. The next is variable zed that represents the list 1 2 3 and again variable W refers to the list 1 2 3. So here you can see that we have used the collection type data that is the list and so this Z and W variable refers to the list. The collection type variable refers to the object and keep in mind that this collection type data though values are being same every time created new in the memory location. So Z and W refers to the different memory location though they are having the same value. So after fixing these four values we have printed all these four values and next now first we have used the is operator. So you can see that we have used X is Y. So, Python will check if X and Y refers to the same memory location. So, here X and Y referring to the variable. So, yes, these two are referring to the same value only. So, here we will get the output true. Next, we have checked if Z is W. So, Z and W are referring to the same values. But these two are being the collection type. So, the memory location of both these will be different. So, we will get our output to be false. Again keep in mind that these identity operators are checking the memory location of the variables if they are same or not. Next is is not operator. So first we have checked X is not Y. But we have already seen X and Y are referring to the same value in the same memory location. So in such case we will get our output false. And the next is Z is not W. So yes Z is not W. Both are referring to the different locations. So here we will get our output true. Now to check the output again run the program. So in the terminal you can check that X and Y are referring to the same value or the same memory location. So we are getting the output true. Whereas Z and W are referring to the different memory location. So we are getting the output false. So if anytime in our program if you want to check that the variables that we have created are referring to the same memory location or not then we may use these identity operators. Go through all these different data types again and practice them in the separate files so that you may be familiar with the output that you are getting based on the different values. Looking forward to see you all in our further session. Till then thank you. Hello everyone. In this video we will understand operators precedence in Python programming. In Python operator precedence determines the order in which operations are evaluated in expression. Understanding the precedence helps avoid logical errors and write efficient bug-free code. Let us first see operators precedence table. Here you can see that the multiple operators are provided in the column from highest to lowest order. That means if we have written any expression combining all these different variables, values and operators then first precedence will be given to the parenthesis then to the exponent and same way in the downside you will find that from highest to lowest order multiple operators are provided. So while executing any expressions Python is keeping in mind these operators precedence to get the output. Let us understand this precedence with the example. So we will go to the first example. Here you can see that the expression is provided and answer is stored into the result variable. So here result equal to 5 + 10 into 2 greater than 25 and 15 / 3 equal 5. So here multiple operators are combined in combination with the values. So to get the output for this expression we must need to follow the operator's precedence based on the table. First we need to perform multiplication operation and the division operations. So first step will be the multiplication. So 10 into 2 equal to 20. Second will be division and for that 15 / 3 equal to 5. So in place of 10 into 2 we will get 20. In place of 15 / 3 we will get 5. Next operation will be the addition operation. So 5 + 20 equal to 25. After addition operation, now the remaining operators are greater than and and equal equal operator. So now first evaluate the greater than operator. So for the comparison 25 greater than 25 evaluates to false. Same way five equal equal 5 evaluates to true. Now the final expression remaining is operator and for that the final values available are false and true. So this will evaluate to false. So finally these many steps are followed by the Python and we will get the output to be false. To understand Python operator precedence clearly let us take the second example. So in example two again you will see multiple operators are provided. Looking at this expression we can see that the parentheses are provided in this expression. So first we will execute the parenthesis. The execution of parenthesis will be 5 + 10 = 15 and 3 + 2 = 5. After that we will perform the multiplication operation. So 15 into 2 = 30. Next division operation. So that is 15 / 5 = 3. Next again we will perform comparison operation. So that is 30 greater than 25 evaluates to true. And next is equality check that is 3= 3 and it is evaluating to true. last operation remaining that is the logical or operation and the values are true or true and this is evaluating to true. So at the end we will get our output to be true. So I hope you got the idea how this operator precedence table is useful to execute a different expressions based on the operators provided. Now to check the output of both these example, let us go to the VS code. And here we have provided the same example, example one and the example two. So for that let us run the program. So as you can see for the first example we are getting the output false and for the second example we are getting the output true. So with these two example I hope you got the idea how these operators precedence table will be useful to you to solve different expressions. I suggest you to practice more expressions and check the results to build your confidence. With the end of this video, I would like to congratulate all and making it this far. Learning Python or any programming language is like building a foundation for endless possibilities. By understanding operators and expressions, you have unlocked one of the most critical tools in your programming journey. Remember, every complex programming starts with mastering the basics. And you are doing just that. Today you have taken another step closer to becoming a confident Python programmer. The path may seem challenging at times, but each concept you conquer build your confidence and opens doors to innovation and creativity. Keep pushing forward, keep practicing, and most importantly believe in your ability to learn and grow. Your efforts today are saping you into a problem solver of tomorrow. Stay curious, keep coding and I will see you in the next video where we will dive deeper into Python. Until then, take pride in your progress and never stop exploring. You have got this. Hello everyone. In this video, I will teach you how to learn Python using Jet GPT. To use Jet GPT, we need to provide a prompt or information in a clear way to get the AI output. Prompt in Jet GPT is the input or question provided by a user to initiate a conversion or request information. It act as a starting point for generating a response. The quality and clarity of a prompt directly influence the relevance and accuracy of the AI's output. Prompts are important because they are guide the AI on what the user needs, ensuring concise and useful response. A well structured prompt minimizes ambiguity and helps avoid incomplete or incorrect answers. For example, explain Python data types with examples. This will provide better result than tell me about the data types. So here JVT gets confused. You are talking about the data types of which language. So it is better if we provide the clear information to the Jet GPT. By refining prompts, user can unlock Jet GP's full potential making it a powerful tool for learning, problem solving and creative task. Clear prompts save time, enhance productivity and make interactions more engaging and effectively. For your reference, some of the prompts are provided over here to get the output from the chat GPT. So let's go to the chat GPD and provide some important prompts to get the output. Suppose I want to learn the numeric data type from CGP in Python. So for that we will provide the information such that explain Python's numeric data types with examples and hit enter. So here you will get the output with proper information and some of the examples also. Here you can see that Python has provided some of the important information regarding the numeric data types and also the examples are provided over here. Next, if you want to learn arithmetic operators in Python, so you may ask explain arithmetic operators with example and hit Enter. Here that GBT has provided all the arithmetic operators with the examples. And if you look at the prompt here, we have not specified the programming language. But from the previous prompt, CHP has automatically detected that we are talking about the Python language. So you can understand that each prompt may be relevant to the previous prompt also. So you will get the output accordingly. Same way you can understand all the different operators using this jet GBT also. Next suppose we want to understand what are the strings in Python. So you may ask the same to the J GBT. So we may provide the prompt what are strings in Python and hit enter. So here so much information is provided by the JG GBT with regard to the string. Let us again take one more prompt. Suppose we want to understand the basic input and output in Python. So we will provide the information explain basic input and output with one example in brief in Python. So here you can see that the chat GPT has provided the concise information regarding the input and output that we have already discussed. Using the input function we may get the input from the user and using the print function we can get the output on the screen. I hope these with these examples you understood how to make use of Jet GPT to learn more about the Python topics. So the next time you are reviewing topics like commands, input or output or operators, try using Jet GPD. Just type your question and let it guide you. Remember, learning is a journey and every question you ask brings you one step closer to mastery. I will see you in the next session with more Python concepts. Until then, make Jet GPD your learning partner and strengthen your skills. Hello everyone, welcome to module two of our learning journey. This is control flow and loops. In this module, we will dive into one of the most exciting and essential aspects of programming. Control flow and loops form the backbone of decision-m and repetitive task in any program. This module will equip you with the tools to make your program smarter and more efficient. We will learn how to guide the flow of execution in your code using conditional statements like if, else, and al if. And we will explore loops such as for and while that allow us to handle repetitive tasks seamlessly. By the end of this module, you will not only understand the concepts but also be able to apply them to solve real world problems including practical examples in mechanical engineering, data analysis, and automation. So let's get started. And as always, feel free to experiment along the way. Remember, this is where your programs truly start to think for themselves. Let's unlock the power of control and automation together. Let us start with the conditional statements. Conditional statements allow a program to make decision based on conditions. They control the flow of execution depending on whether condition evaluates to be true or false. So there are different types of conditional statements. From that the first one is the if statement. Now to use the if statement in Python programming we need to use a proper syntax. So first we will write if in a lower case and then we will provide the condition using some of the conditional operators. Then colon symbol is important. After that we will provide the enter and by providing the indent we will write the code that we want to execute if the condition is true. So if the condition is true then and then only the code inside the if condition will get executed. Second statement is the if else statement. So as you can see the if condition will remain same but now again we will also provide the else condition. Here keep in mind that the indentation provision is most important. So in else case as you can see we will write the else in lower case. Then we will use the colon symbol. Here we will not provide any condition and this else block only gets executed once the condition is false. So we may use only if statement also and if needed we can use the combination of if else statement also. Now the third possible if else statement is with the use of l if statement. So in programming there may be a possibility that in place of one condition we want to check for more than one conditions also. So to check four more than one conditions we will use if l if else case. So as you can see first we will provide the if condition. So if first condition is not satisfied we want to check for the second condition then we will write al if l if in the lower case then condition two and again if the condition two is satisfied then the code will gets executed inside this if statement. In place of second condition, if you want to again check the third condition also, then again we will also write al if then we will provide the condition three. So again if condition three is valid then the code executes inside that condition three or at last if any of the condition is not executed then the else case gets executed and this code is only executed if all the conditions are false. So this if al if case is useful we want to check for more than one conditions simultaneously. Now the last case is the nested if else statement. Nested if else statement means we will use if statement inside another if or we may use if else inside another else. So if you want to check one condition inside another condition, second condition inside third condition. So to check multiple combinations or multiple conditions depending on the another condition these nested if else statements are useful. So here as you can see if condition one is true then and then only interpreter will go inside condition two. Now again if condition is true then and then only the code executes inside the condition true. If the condition two is false then the else block gets executed. Same way you can see that the else case is provided for the outer if and if condition one is false then and then only the outer else gets executed. Inside else case again we have provided the condition three. So if that condition three is true then and then only the code inside if gets executed. Else condition three is false then the final else block gets executed. So as you can see multiple if else combinations can be used inside if else based on the requirement. So this case is known as the nested if else statement. Here the key point to remember is Python uses indentation to define the blocks of code under each condition. You can also combine multiple conditions using and or and not operators also. Let us understand all these different statements using the actual code. So for that go to the VS code. Here as you can see first example is provided for the if case. Here we have mentioned if the condition provided is five greater than three. So if this condition is true then the block gets executed and we will get the output five is greater than three. If this condition is false so you can see that here else block is not provided. So we will not get any specific output. Second is if else example. Here you can see that we have provided both the block. If five greater than 10 then we want to print five is greater than 10. If this condition is false then compiler will go into the else block. And here if we will get the output 5 is not greater than 10. So in our case 5 is greater than 10. This condition is false. So else block gets executed and we will get the output five is not greater than 10. So this specific statement will be our answer. Third is if l if else statement. So here you can see that we have stored value age to be the 20. Now if condition is provided age is less than 18. We will get output you are minor. But if you want to check for the second condition l if age equal equal 18 then we want to print you just become an adult. And if none of these conditions are true then compiler will go to the else block and here it gets printed you are an adult. So here our variable age is equal to 20. So let us check first 20 is less than 18 condition is false. So we will move to al if here 20 equal equal 18. Again this condition is false. So we will go to the else block. And here we will get the output you are an adult. At last nested if else statement here as you can see we have provided marks equal to 72. Now we have provided first condition if marks greater than equal to 75 then it will print you achieved distinction. If that condition is false then we have provided the second condition. L if marks greater than equal to 60 then it will print you passed with the first class. Within this statement if we want to also check if the marks are greater than 70 or not. So inside al if statement we have used again if else block. This is known as the nested if else statement. So if marks greater than 70 then it will execute your score is above 70. Else it will print your score is between 60 and 70. Now suppose if and l if both conditions are false then interpreter will go to the else block and here it will print you did not achieve first class. So let us again check with the variable marks are the 72. So let us check first condition. 72 greater than equal to 75 false. We will go to second step. 72 greater than equal to 60. True. So it will print you passed with the first class. Again inside that it will check mark greater than 70. So 72 greater than 70. True. So again it will print your score is above 70. If is executed. So else block will not get executed. Same way ell if statement is satisfied. So else block will not get executed. So our output will be first you passed with the first class second and your score is above 70. So I hope you got the idea how this syntax will be helpful to get the output based on the condition. So let us run the program. So here as you can see that based on the conditions we will get the output five is greater than three five is not greater than 10 and same way multiple outputs are provided over here. So I hope you got the idea how these if else statements are useful to get the output based on the different condition. Practice these if else statement to get more familiarity with this syntax. Keep in mind indentations are most important. If you will not provide the indentation then you will get the error. So let us say suppose at the first if five greater than three is mentioned and I am removing the indentation with the print. So here directly you can see that the error is highlighted with the red line and it is mentioning that expected indented block. So it is much more important to follow the proper indentation process to get the output. In our next session, we will try some of the another important examples also with the if statement considering the mechanical engineering examples. Hello everyone. Today as we continue our journey of learning programming and logical thinking, I want to bring something exciting and practical to this table. Our next practice will focus on writing if program. But this time we will integrate mechanical engineering concepts into our coding exercise. So let's directly jump to the practical examples related to the mechanical engineering. Go to the VS code. Here as you can see we are having the first example. Machine requires regular lubrication if it operates continuously for more than 8 hours a day. Now we need to write a program that takes the operating hours of a machine as a input and checks if it requires lubrication or not. So as you can see in the statement we need to take the input for the Rs. As we take the input we know that the input will be by default in the string data type. So we need to convert it into the numeric data type. It may be a int float based on requirement we need to change the data type then we put the condition if ours is more than 8 means Rs greater than 8 then we will write it requires the lubrication. else we will write we do not require the lubrication. So for that let us check the code. As you can see we have provided the one variable operating hours equal to we have converted the data into the float data type. Input enter the number of hours the machine operates daily. Then using the if else conditions we have printed some data. So if operating hours greater than 8 colon we will print the machine requires regular lubrication. Else we will print the machine does not require lubrication. So let us run the code. We will enter the number of hours. Let's say the number of hours being the seven. Press enter. So here you can see the output. The machine does not require lubrication as the value entered is 7. 7 greater than 8. Condition is false. So we will go to else case and here it will print machine does not require lubrication. Let us again run the code. Now pass the value greater than 8 being 10 and hit enter. So now you can see 10 greater than 8 condition is true. So it will print the machine requires regular lubrication. Based on the conditional check outputs are required. So in such case these if else statements will be very much helpful. Let us go to the next example. Here you can see that the example provided is the mechanical part is considered safe for use if its stress level is less than or equal to 200 megapascal. We need to write a program based on the stress value as input and output will be whether the part is safe or unsafe. So same way here first we need to assign the stress value using the input. we will convert it into the required data type. Then based on the if else condition, if our condition is the stress less than equal to 200, then we will print component is safe. Else we will print the component is unsafe. Again check the solution here. You can see that we have defined the variable stress value equal to float. Input being the enter the stress value for the mechanical part value should be in mega pascal based on the condition. If stress value less than equal to 200 colon then it will print the mechanical part is safe. Else it will print the mechanical part is unsafe. Again let us run the code. Now enter the value to be 150. Hit enter. The output will be mechanical part is safe for use. Same way run the program again. Now input the value 300. Enter. So now the output will be the mechanical part is unsafe for use. So based on the input value we will get either condition being the true or either condition being the false. The different outputs will be printed on the screen. Now again go to the third example. The cooling system operates at a different efficiency levels based on the ambient temperature. Here the different conditions are provided. If the temperature is below 20°C it will print high efficiency. If it is between 20 and 40° C, so we need to print moderate efficiency and above 40° C, we need to print the low efficiency. [clears throat] So we need to write a program to take the ambient temperature as a input and output will be the systems efficiency level based on the conditions. So here as you can see we need to have more than one condition in our program. So in such case we need to use the concept of if, element, else. So again let us check the program. So here as you can see first we have provided input being the ambient temperature. Temperature value is converted into the float based on the input. Now we have provided the multiple conditions. If our variable where the temperature is stored that is ambient temperature is less than 20. So it will print the cooling system is operating at a high efficiency. Al if as we are having the second condition so the condition used is al if so here the value provided is if the value is between 20 and 40 so we have mentioned 20 less than equal to our variable that is ambient temperature again less than equal to 40. So if our value is between 20 and 40 so it will print cooling system is operating at moderate efficiency. else. If both conditions are not satisfied then we will go to the else case and it will print the cooling system is operating at low efficiency. So again keep in mind at each and every place indentations are important, colons are important without these always we will get the error. So let us run the program to check the output. First let us input ambient temperature to be 15. Hit enter. So now once we enter the value 15 15 15 will go and get stored into the ambient temperature the 15 less than 20 condition is true. So it will directly execute the data inside that condition and it will print it is having the higher efficiency. Once any of the condition is satisfied the remaining cases will not get executed and we will directly get our output. Again run the program to check for the second case. Let us enter the value 26. Hit enter. So now first case 26 is less than 20 false then it will check for the next condition 20 less than or equal to value being 26 less than or equal to 40. So this condition is true 26 is in between 20 and 40. So based on this condition it will give us the output that is the moderate efficiency. Again run the code and now enter the value being greater than 40. Let us say the temperature being the 50°C. So now 50 is less than 20 condition is false. 20 less than or equal to 50 less than or equal to 40. 50 is not in between 20 and 40. So again this condition is false. Finally we will go to the else case. So in else case it will print the cooling system is operating at a low efficiency. So based on our input interpreter executes the data and we get the output based on the conditions provided in the program. So here keep in mind that data type conversion is important. Then and then only we will get our required output. Now let us go to the last example. So here again as you can see the statements are provided. The statement is in a mechanical assembly a bolt is categorized based on its diameter. Here it is mentioned if the diameter is greater than 10 mm then again we need to check. First condition is check for 10 mm diameter. Within that we need to again check inside that condition if it is a high strength bolt or standard bolt. So condition given for that is if the value of tensile strength is greater than equal to 800 megapascal then it is a high strength bolt. Else it is a standard bolt. Next, if the diameter is less than or equal to 10 mm, then we need to check again. In that case, we need to check if it is a precision bolt or a general purpose bolt that we will decide based on the tolerance value. So, this data is given. Now, the program requires us to take the diameter, tensile strength and tolerance as input and categorizes the bolt based on the given data. So, let us start the program based on the given data. So first we need to take input as a diameter. So diameter equal to we will convert it into the float data type. So we will write float to take the input keyword is input and let us mention enter the diameter of bolt. Once we get the value of the diameter we need to check for the condition. So let us check for the condition. So if diameter is greater than 10 mm. So diameter is greater than 10 mm. Then what we need to do? So inside that again we will check if it's high strength bolt or standard bolt. So inside this we will again ask the user to input the value for the tensile strength of the bolt. So let us take the value tensile strength equal to convert the value into float. Let us take it as a input. Enter tensile strength of bolt and it should be in megapascal. Now based on the value again we need to check if the value of tensile strength is greater than equal to 800 then we will print it is a high strength bolt. Else colon we will print it is a standard bolt. Now here first section is over. Here we have used if inside if. So this is the case of the nested if else statement. Now we have completed the inside if else statement. Now for the outer if we need to check for the value less than or equal to 10 mm. So the else case will always consider for the less than equal to 10 mm. So in else case we need to again take the input that is the value of tolerance. So we will store the value of tolerance convert it into the float. Take the input. Enter. Tolerance of the bolt. Now we will check if tolerance value is less than equal to 0.01 mm. So we will print precision bolt. Else we will print generalpurpose bolt. So based on our input compiler will go through these certain statements and it will give us the output based on the diameter, strength and the tolerance value provided. Let us clear this to get the proper idea. Run the program again. We have asked to enter the diameter of bolt. Let us say the diameter of bolt being 8. As the value of diameter is 8, it will check if 8 greater than 10 condition is false. So we will directly move to the else case. In else we have asked to enter the value of tolerance. So next we need to enter the value of tolerance. So let us say the value of tolerance being the 0.02. 02 mm and hit enter. So here you can see that 0.02 is less than or equal to 0.01 condition is false. It will go to the else case in in else block it will print the generalpurpose bolt. Again let us run the program to reverify the other details. So again run the program. Enter the diameter of bolt being the 12 mm. So 12 is greater than 10. True. It will go into the case of tensile strength. Now enter the value of tensile strength. Let us value being the th00and. Hit enter. So again check inside that 1,000 is greater than or equal to 100. True. Then it will go inside the if case and it will print high strength bolt. So based on the entered values program will decide which output is required. So same way in the case of automations or in the programming based on the input value received from different sources we can decide the type of content or the type of values required for our program. You may try for different variations also for your practice purpose to get the idea how we are getting the output based on the execution of the program. So with these combinations of examples, I hope you got the idea how to implement the if else statements and its logic based on the requirement. So these examples have not only enhanced our understanding of conditional programmings but also so how programming can be a powerful tool for engineers. As we move forward, I encourage you to continue experimenting. Take the concepts we discussed, expand on them and try applying them to other areas of engineering. The more you practice, the more confident and the skilled you will become. Let's keep this momentum going as we take on even more exciting programming challenges in the future. Looking forward to see you all in our further sessions. Till then, thank you. Hello everyone. Welcome to today's session where we will dive into the essential concept in programming that is the loop statements or the loop structures. If programming is like solving puzzles, then loops are the tools that help us repeat certain task efficiently, saving the time and effort. So before we begin, let me ask you a quick question. Have you ever encountered a situation where you need to perform the same calculation or operation multiple times? Whether it's calculating the forces for different loads, simulating processes and mechanical systems or even or even repeating task in daily life, we often deal with repetitive actions. In programming, loop statements help us to handle such scenarios. With loops, we can automate repetitive task with just a few lines of code. Instead of writing the same logic over and over, we can use for loops or while loops to let the computer do the heavy lifting. So in this session we will understand how for loops work, understand their syntax and most importantly practice some of its basic examples. So this for loop is used to iterate over a sequence specific like list, tpple, string or range. The basic syntax of for loop involves we need to use the keyword for then after any variable name which refers to any of the iterable. It might be the data of list tuple string or any of the range. So we will write for variable name then keyword int then after the list tuple or string that we want to represent or the any iterable that we want to represent from which we want to use the data then provide the colon symbol then hit enter and providing the indentation you may provide any number of statements that you want to repeat for that number of series or for that number of iterations. So here the key components are variable, iterable and the statements. So a variable is a placeholder that takes on the value of each element in the iterable. So if let us say in iterable values available are 10, 20, 30, 40. So the variable refers to the each individual element one by one. So first it refers to the 10 then 20 then 30 and then 40. The next is iterable. It is a sequence or collection to iterate over and it includes the list, tpple, string and range. And the last one is a statement. So it is the block of code to execute for each iteration. And this block must be indented. That is the most important part. To run the simple iteration process using the for loop. Go to the VS code. Now suppose as an example first we want to iterate over a list. We are having the list of materials and it is stored in the variable name materials equal to the data is stored into the list. So within square bracket we will provide our data. The material being steel, aluminum comm, copper. Now suppose I want to print each individual element of this material. So the printing of element is the repeated task and these repeated task can be performed using the concept of for loop. So to use the syntax hit enter we will write the keyword for then we will create one variable which will refer to the each individual element available in the materials section. So let us say 4x in now from which data we want to consider each element. So that will be from the materials list. So we will write in materials and then colon symbol. So here you can see for X in materials means X refers to each individual element available in the materials. So X will refer to steel then aluminum then copper. Here our objective is to print each element. So we will print let us say the material comma the variable being the X. Now run the program. So here you can see that the material first it will take the value X. X refers to the first element that is steel. So material steel. Next it will again run the program. Then the next material is aluminum. So material aluminum. And the last one is the material copper. So here X refers to each element available and it will continue till the end of the element available in the list or tuple or the given iterable. I hope you got the idea how to use the syntax of the for loop to iterate over the data available in our iterable. In our next session, we will continue with some of the important part that is useful into the for loop that is the range function and its syntax. Hello everyone, in our previous session we discussed about the for loop and its syntax. Now we will understand the range function that is used with the for loop in combination to again give us the certain data. So the range function in Python is used to generate a sequence of numbers and it's commonly used with the for loop to iterate over a specific range of numbers. So as a syntax of the range as you can see we will first write a range in lower case and within round bracket we will provide the three data based on the requirement that is the start value stop value and the number of step in which increment or decrement is required. Here start refers to the starting value of the sequence and the default value is zero if not specified. So if we have not specified the start value then the default value will be considered as the zero. Next, the stop refers to the ending value of the sequence and it is not included in the range. So the last value that is the stop value is excluded from the range. The next is tab and it is the difference between each number in the sequence and the default value is one if not specified. Now let us use the range function in the real examples. So for that go to the VS code. Suppose we want to print the simple range having the default start and step value. So for that we will use the for loop. So for i in we will use the range and the value provided is the five then colon and we want to print the numbers. So we will type print i. So here as you can see that we have provided only the fixed value that means it will accept the start and step value as the default value and here five is being the end value. So default value will be zero for the start and the step default value will be 1. So as you can see we will start from the i. The value of i. Initial value being the zero. So first it will print zero then 1 then 2 3 and four. This loop will get repeated for five times as we have provided the end value being the five. So let us run the program. So here as you can see that it will print 0 1 2 3 and four. So keep in mind that the default value for the start being the zero and the default value for the step being the one. Now suppose if our need is to specify the start and stop value. So for that again we will use the four i in range. Now here we will provide the starting and ending value. So 1 to 6 colon and again our objective is to print I. So here you need to keep in mind that whenever we are providing the range with the starting and stopping number it will start from one it will include one but the last ending number six is not included. So it will start from 1 up to the five only. So run the program. As you can see over here it will print 1 to five but six is not printed because the end number is excluded from the given range. Now let us say suppose our requirement is to provide the start stop and the step also. So for that we need to again rewrite our for loop and let us say suppose we want to provide the starting value. So 4 I in range the value being the 0 comma 10 then colon and again we want to print I. So what is the meaning of this statement? So the starting value is zero, ending value is 10 and the value gets increased by two. So first it will print zero then increment of two. So 2 then 4 6 8. But again as we know end number is not included in our series or the sequence. So it will print up to the 8 only. So again let us run the program check the output. So here as you can see it will start from zero then 2 4 6 and 8. So if needed we can also specify this step size also based on our requirement. Up to now as you can see we are printing our data in the forward direction only. It means in the incremental order only but there may be also chances that if we want to print the data in the reverse order or in the reverse range also. So it is also possible. For that we will provide the step size with the negative value. So again let us start the for loop. So for i in range let us say the starting value is 10 ending value is zero and I need the decrement of minus2. Provide colon and I want to print I. So it will start from 10. It will not include zero. So 10 then decrement of minus2. So it will print 8. 10 6 then 4 then 2. But zero is not included. So it will print value up to the two only. So run the program and check the output. It will print the data in the reverse order that is 10 8 6 4 and two. So I hope you got the idea how to make use of the for loop in the combination of the range function also. Other than this there is also possibility that you can loop through each character available in the string also. So to understand that again let us take one example. Suppose it is being our example six. Objective is to loop through strings. Suppose we are having the name equal to Python. Now we want to iterate through each character available in the string. So for that we will write four. Let us say the variable name being the care in. Now the iterable being the variable name then column. And I want to print each character. So let us print the value care. Again run the program. So here as you can see that it will execute code for each different character and it gets printed separately based on our program. So this for loop is useful to iterate through some of the iterables also that may be the list tle then string and we can also get the certain range of data using the range function. So as you can see we started by understanding the basics of for loops which serve as one of the most powerful tools for handling the repetitive task in programming. We then explored the range function which simplifies the iteration by generating a sequence of number in a highly flexible way. So together these tools allow us to tackle complex problems with precision. As you continue to explore the loops, challenge yourselves to write programs that automate task and solve engineering problems more efficiently. The more you experiment with the tools like for loop and range, the more confident you will become in leveraging the programming to simplify complex scenarios. I look forward to seeing how you use this concept in our future programs. Also in our next session we will continue with some of the mechanical engineering related examples to use the concept of for loop. Welcome back everyone. In this session we are going to take some of the practical examples using for loop in the context of mechanical engineering. In the field of mechanical engineering for loops can be used to analyze stress distribution, calculate temperature, optimize designs and there are many different possibilities. Let us go to the VS code to take some of the examples. As you can see in the first example, we have been given the statement. Calculate the stress distribution across a 10 m long beam under a uniform load of 5,000 Nton. And it is having a constant cross-sectional area of 50 mm². The formula is already given to us that is stress equal to load upon area. And we have to calculate the stress at each meter along the beam's length. and we need to assume a uniform load distribution and consistent cross-sectional area. So our objective is to display the stress values for each meter of the beam. So as we know here the major parameters are the length of beam being the 10 m load being the 5,000 Nton. So we need to calculate the stress at each meter of the beam. So we need to iterate from first meter, second meter, third, fourth and same way we need to go up to the 10 m. So let us first create some of the important variables. So as you can see we have defined load being the 5,000, area being 50 and beam length being 10. Now to calculate the stress along the length of the beam, we need to start our for loop starting from 1 m up to the 10 m. So let us continue writing the for loop. So as you can see for i in the range 1 to beam length + 1 that means 1 to 11. So our loop will start from 1 up to the 10. Within this for loop our requirement is to calculate the stress. So the next iteration is stress equal to load divide by area. We have already defined the value of load and the area. And here it is clear that the equation does not depend on the length. So for each meter the value of stress being the same because the load is uniformly distributed. At last we are printing the data stress at specific meter we want to print. So we have provided the value of I. So it will print stress at 1 m. Then the value of stress that is being the based on the calculation. So 5,000 divide by 50 the value. Then after it will print the megapascal that is the unit. Let us run the program to check the output. As you can see the data is printed for each meter that is stress at 1 m 100 megapascal at 2 m 100 megapascal. So same on up to 10 m we will get the same value of the stress as the load is uniformly distributed and it is having the constant cross-sectional area. So using these three lines only we are able to get the output based on the iteration of the for loop. Let us again consider the second example. So the statement given is we need to calculate temperature change along a metal road. A 10 m long metal road is exposed to a constant heat source causing a uniform temperature gradient along its length. The initial temperature at one end given is the 20° C and the temperature increases by 5°C per meter. So we need to write a program to calculate the temperature at each meter along the road. The formula given is temperature equal to initial temperature plus rate of change multiplied by the distance. So our objective is to print the temperature for each meter along the road. So here as you can see again our requirement is to start our for loop from 1 to 10. But the data that we need to calculate is different based on the requirement. So first let us define the variables. So variable being initial temperature 20, rate of change five and road length being the 10. Now using the range function and the for loop we can iterate over each meter of the given road. So let us continue writing the for loop. So as you can see for I in the range 1 to road length + 1 road length being our variable. Next we need to calculate the temperature. So the temperature being initial temperature plus rate of change into now the distance and the distance is increased every time by using the variable I. So we are multiplying this with the variable I. After calculating the temperature we will print the temperature. So again using the print function we have printed temperature at specific meter. So to indicate different meters 1 2 3 likewise we have provided the variable I and the value of temperature that we are getting that will be printed along with with a specific format to check the output. Let us again run the program. So as you can see the temperature at 1 m is 25°C and the temperature increases by 5°C per meter. So accordingly you will find the increment in the temperature in the output. I hope you got the idea how this for loop is useful to iterate over a data perform repeated calculation and solve complex problems efficiently. As we have seen today the power of Python lies in its ability to automate repetitive calculations, analyze data and solve problems efficiently. I encourage you to think about the processes you work with in your projects or studies and consider how programming can simplify that data. The more you practice, the more you will see Python becoming a valuable tool in your engineering toolkit. I hope these examples inspired you to explore even more applications of Python in your field. Keep experimenting, keep learning and see you in the next session. Welcome back everyone. Today we are diving into one of the most powerful tools in Python that is while loop. Unlike the for loop which is ideal for situations where we know the number of iterations beforehand. The while loop is perfect for scenarios where the condition for continuation isn't predefined. Something we often encounter in mechanical engineering task. For example, in engineering simulations, system checks or iterative problem solvings like achieving a target tolerance or convergence criteria, while loops provide the flexibility to keep running until the job is done. So in this session, we will explore the syntax of while loops, understand how they work and tackle some of the mechanical engineering problems using these specific tool. So let us first understand the syntax. To use the while loop first we will type while in lower case. Then after we provide the condition and that condition output should be the boolean. Now if that condition is true then the block inside the while loop gets executed. It may be any statement from statement one to the number of required statement. So this block of statements gets executed as long as the condition is true. There may be a possibility that we may update the condition to exit from the loop inside the while loop content. Here keep in mind that all statements inside the loop must be indented and if the condition is never updated to false then the loop will run forever. That means it will go into the infinite loop. So we must need to keep a track of condition also and the track of end condition also where the loop will end. Now these may be increment or decrement also or it may be the change in value also such that the condition becomes false. So let us understand the syntax of while loop using the first example. For that go to the VS code. Here as you can see our problem statement is we need to write a Python program to print countdown from 5 to 1 using a while loop. So the first thing required is initialization. We need to start from the five. So we will initialize our value to be five. So it is stored first into the variable count equal to five. Second requires is the end condition. For that we need to start our while loop. So we will write while then condition and the condition being till what point we need to continue. We need to continue up to one. That means if the value of count that is our variable is greater than zero till that point we will perform certain task. Now what is the requirement? we need to print the number. So print the number we need to print the value of count. So the next statement we have mentioned is using print function we have printed the value of count using a specific content. Now let us say we have started from the five. So that five value go into the while loop. So five greater than zero it is true. Then it will print countdown the value of count being the five. So it will print countdown five. Next we need to go to the other required number that is four. That means we need to reduce the value of count by one. Then we need to have the value three then two then one. That means after each operation we need to decrease our value by 1. So after printing statement we have decremented our value that is the count minus equal to 1. So now we will start from five then 4 3 2 1. Once the value becomes a zero again it will be stored into the variable count equal to zero then it will pass into the condition. So 0 greater than zero condition is false. As the condition is false we will come out of the while loop. So to understand the output let us run the program. So here as you can see the value printed are countdown 5 4 3 2 and 1. Now suppose if we do not have provided these decrement. So let us comment the same. Now again run the program. So as you can see the loop is started for the infinite number of times. It will continuously print the value five. So this program has gone into the infinite loop. Let us first exit from the program. Now why this has happened? So for this again check the program. The value of count is five. So it will pass over here five greater than zero. True. It will print countdown five. Then again we will go back. Now the value of count being five only we have not incremented or decremented based on requirement. So it will continuously take the value five. For that this condition is always going to be true. So it will print our data for the infinite number of times. So we must need to take the end condition and the requirement of change in value or increment decrement to properly execute our program. Let us take another example of the while loop to get the idea how it can be implemented in the mechanical engineering context also. Here you can see we need to calculate the time required for a cooling process. So certain data is given. A hot metal block is left to cool in ambient air. Okay. The block's initial temperature is 500° C. So let us define the multiple variables in the program and then after accordingly we will start our calculation. So first define the initial temperature. So variable being initial temperature equal to 500. Then cooling rate equal to 15. Then the surrounding air temperature is given to be 30°C. So let us represent it as ambient temperature equal to 30. Now we need to write a program using a while loop to calculate the time it takes for the blog to cool to 50°C or below. Now the initial temperature is 500° C. We need to calculate the time when it will cool to 50°C or below. So let us define the target temperature that is being the 50°C. So variable being final temperature and that is equal to 50. Now to get the data of the time we need to take one counter that will calculate the time. So let us define time counter variable being time equal to zero. define the current temperature that is equal to initial temperature. Now we need to simulate cooling process using the while loop. Here we do not know the exact number of iteration but we know the end condition. The end condition is if the current temperature is greater than the final temperature that is greater than 50 then at all that time we need to print the time required and the temperature at that specific time. After that we need to reduce the temperature also based on the cooling rate and the cooling rate provided being the 15°C per minute. So we will reduce the current temperature by minus5 and with this reduction we will increase the time being the 1 minute. So for that let us start our while loop and this while loop let us comment the same while loop to simulate pulling process. Write the while loop. So we will write while then condition. condition being a current temperature greater than final temperature then symbol colon. If this condition is true then we will print. Let us provide the proper formatting. So f within double quote define time. Then we will print the actual time that is the variable. Then it will be in minutes. So let us define minutes. then temperature colon again print the actual value that is the current temperature and it will be in degree Celsius. So define degree Celsius. Now we need to update the current temperature. So current temperature will get reduced by the cooling rate. So minus equal to cooling rate. So this statement indicates the reduction in temperature. So let us comment reduce temperature. Next we need to increment the time counter also. So let us define time plus equal to 1. And this indicates the incremented time counter. So this process will continue till the current temperature is being greater than final temperature. After completion of the while loop, let us remove the indentation and print the final result. So comment print final result. We need to print this same data. So let us copy this data. Print over here again that will indicate the final time and the final temperature after completion of that while loop. And let us again provide the final printing statement which indicates our exact output. So formatted to the metal block has cooled to certain temperature in certain time. So for that let us define the temperature degrees C in given time. So time being the variable and unit being the minutes. So here as you can see we have prepared one program which will simulate the decrement in time based on the given data. So run the program. So here as you can see based on the iteration at the zerooth minute the temperature being the 500°C accordingly based on the cooling rate it will reduce the temperature and to reach the temperature of 50° C as you can see the metal block has cooled to 50°C in 30 minutes. I hope you got the idea how to use the while loop to run the Python program based on the requirement. Remember the key to mastering while loops lies in understanding the condition and ensuring it eventually stops preventing the infinite loops. So keep practicing and you will soon find yourself using this concept seamlessly in your projects. I hope this session inspires you to tackle more complex engineering problems with the confidence. With the end of this, see you all in the next session. Hello everyone. In this session, we will discuss about the important part of looping that is the loop control statements. We will explore the break and continue statements which will allow us to fine-tune how our loops operate. These statements give us the power to alter the normal flow loops making them incredibly versatile for solving the real world problems. Also, for instance, you might want to stop a loop early when the specific condition is met or you may want to skip certain iterations that don't meet your criteria. So, by understanding and applying these control statements, you will be able to make your code more efficient and better suited to handle the complex situations. Also, let's get started and see how these statements can bring precision to our loops. To understand the break and continue statement, we will take examples and understand this concept with that same examples only. So go to the VS code to experiment the same. So here the first example is for the break and this break statement is used to exit the loop completely regardless of whether the loop condition is true or not. Once the break statement is executed, the loop stops but the remaining part of the program continues with the given data. So as you can see in the example, the for loop is given for i in range 1 to 10. Here the condition is given if i= 5 then break. The loop will start from 1 then 2 3 4. Once the value five comes it goes into the if. So 5= 5 that is true and it will execute the keyword break. So the break means the loop stops and the remaining part of the program continues. So let us run the program here. As you can see it will print up to 1 2 3 4 only. As the value of five comes we come out from the four loop and after for loop there is no any other data given. So the program stops. Let us change the data. Suppose after for loop I am writing the printing statement program over and I am changing the condition being the if I equal equal 6. So now our program will start from 1 to 5 at the six break gets executed. We come out of the for loop and the remaining part of the program continues. So again run the program here you can see that the loop started from 1 to 5. The range is given from 1 to 10. But with the satisfaction of the specific condition and the execution of the break, we exit from the loop. After exiting the loop, the program continuous. So that's why as you can see outside the for loop in the program, the statement return is program over. So this statement also gets executed in the program. So the last statement is program over and then program stops. So this break statement is very much helpful when we want to stop our iteration based on the satisfaction of the specific conditions. Let us go to the continue statement. This continue statement skips the rest of the code inside the loop for the current iteration and goes back to the loop condition to continue with the next iteration. That means in the case of break loop we are exiting the loop but in the case of continue statement we are skipping one specific iteration based on the satisfied condition only. After skipping that iteration our loop will continue for the remaining number of iterations. Consider the example as you can see for loop is started from 1 to 10. Here if I equal equal 5 that means continue. Continue means we will skip the current iteration and go to the next iteration. So in this program the loop skips the printing of five because of the continue statement but continues the loop for the remaining values. Run the program and check the output here. As you can see it has printed 1 2 3 4 but five is skipped and then again printed 6 7 8 9. So with the satisfaction of the specific condition the continue statement skips the current iteration and go to the next iteration. It do not directly stop the loop. So the break statement is useful to stop the loop. Whereas continue statement is useful to skip the specific iteration based on the requirement. So here we have explored the powerful concepts of loop control statement that is break and continue and learned how they can help us to fine-tune our loops to solve specific problems more efficiently. These tools are very much useful for optimizing some of the processes and avoiding unnecessary iterations. Also I encourage you to practice these concepts and experiment with applying them to various problems in your field. with time and practice you will see how much they can enhance your programming skill and problem solving abilities. So keep exploring, keep coding and I will see you in our next session. Welcome back everyone. In this session we will discuss about the nested loops. Nested loops allow us to handle complex and repetitive task by combining the loops within the loops. This concept is same as the nested if else case in which we have already understood how to use the if inside the if. So in the same case we will use the loop inside the loop. This concept is especially useful when we are dealing with the matrix grids all the multi-dimensional problems related to the mechanical engineering field. It may be helpful to solve intricate problems in mechanical engineering like stress distribution across multiple sections or flow simulations in a pipeline system. In this session, you will understand how nested loops work, how to structure them effectively and how to apply them in the programs based on the requirement. Let us first check the syntax for the nested loop. So as you can see suppose we want to use the for loop inside the for loop. So we will write first for outer variable in outer range colon. Inside that we will again write indented for inner variable in inner range. Then provide colon and within that indented we will write our code that we want to execute. Here the inner loop runs completely for each iteration of the outer loop. Let us understand this syntax using the practical example. So for that go to the VS code here. Suppose we want to print the multiplication table using the nested loop. If we are about to represent our data in two dimension, then the outer loop controls the number of rows and the inner loop controls the number of columns. As we want to print the multiplication table, the number of rows will be from 1 to 10. So to keep the track of number of rows, we will write our outer loop. So the outer loop range will be 1 to 10. So for that the syntax will be for i in range 1 to 11. Here 11 gets excluded as we have already understood in the range function. Next suppose we want to write the multiplication table for the numbers 1 to 5. So to keep the track of that numbers we are providing the number of columns. So in the first column we want to write the table of one. Then in second column the table of two and same way in the last column that is in the fifth column the table of five. So to keep the track of five columns we are again writing the for loop inside the outer for loop that is for J in range 1 to 6. So here inner loop controls the columns being 1 to 5. Here we want to print the multiplication table. So we are printing I into J. That means it will print the product of numbers in the same line separated by deps and the data will be printed like 10 rows and the five columns. After the print function as you can see outside the inner loop but inside the for loop we have mentioned the print statement and it ensures that after each iteration of the inner loop we move to a new line. Let us run the program to check the output. So here as you can see in the first column we are getting the table of one then two then three and same way the table of five we have printed. So to perform the operations in the two dimension based on the requirement these nested loop concept is very much helpful during using the nested loop there are some of the key points that one must need to remember. First important point is we need to provide the proper indentation for defining the loop blocks. We must need to avoid the infinite loops by ensuring loop conditions that eventually becomes false. And using this loop concept, we can also iterate over the list, tpples, strings and dictionaries based on the requirement. This concept is very much useful in the field of mechanical engineering where the iteration through time steps in simulation is required and it is used to solve the differential equations also. Thank you for continuing to this session on the looping structures. As we know now the loops are essential for writing the efficient and dynamic programs. So practice what you have learned till now and you will soon find loops becoming an integral part of your coding toolkit. And again keep a note that these nested loop concept is not only for the for loop but you can use the same concept for the while loop also. So you may practice the same. So keep practicing, keep learning and see you all in the next session. Hello everyone and welcome to this session. Today we are going to explore how programming concepts like loop and conditional statements can be applied to solve the mechanical engineering problems. We have already understood how to use the loop and the conditional statements. So let us start our discussion by considering the first example relevant to the mechanical engineering field. So the data is given. We need to inspect the hardness level of a metal shaft at the various cross-section. The shaft is subjected to the different manufacturing process which may result in varying hardness values at the different section. The target hardness level for the shaft is set at 50. So let us define the parameters. The first is target hardness that is 50. Next, we need to evaluate each section's hardness and classify it as low, high or normal based on the comparison with the target hardness. The condition is given. If the hardness is below the target, it is considered low. If it is above, it is considered high. And if it is equal to the target, then it is considered as the normal. The program should iterate through all the sections and display the corresponding classification for each section. Now let us assume we are having the hardness levels at the different sections. So for the five section the hardness values are given. As we want to store all the hardness values and want to compare it with the target hardness level we will store all the similar values into the one variable and for that we will use the concept of list. So define hardness levels equal to let us create a list with the square bracket having the values 45 55 50 48 and 60. Now to indicate the different section let us define the variable section being the starting value 1. Now to iterate through all the hardness levels and compare it with the target hardness we need to use the for loop. So four the value being hardness in the variable of list type is hardness level. So use the same variable hardness levels. Within this we want to print the details based on the comparison. So if hardness is less than target hardness we will print our data in a specific format. So let us type print use the function section then its value colon hardness then again its value then dash and for this condition we need to type the low copy this statement as this will be needed in our further conditions also we need to go for the second section. So we will increase the value of section and if this condition is satisfied we do not need to check for the other conditions. So to skip the iteration we will use the control statement continue. Take the next condition al if hardness greater than the target hardness we will again print the same statement but here we need to print the value I again increase the section plus equal to 1 and continue the iteration. If none of these condition is satisfied, we will go to the else case and here we will print the hardness of the section being normal and again increase the section value to be plus equal to one. So as you can see in the program our program will iterate through each value available in the hardness levels that is 45 55 and so on and compare it with the target hardness. If the value is lower then it will print the low. If the value is higher it will print the high and if it is same then it will print the normal. To check that run the program. So as you can see for the section one hardness is low for the second section hardness is high and for the third section hardness being the same. So it has printed normal. So based on the provided values we are getting our output. So I hope you got the idea how to combine these loop statement and conditional statement to get the fruitful result. We will again discuss about the second example in our next session. Till then thank you. Hello everyone. In this session again we will continue our discussion regarding to the example related to conditional statement and loop statement and the use of same in the mechanical engineering problem. So go to the next example. Here you have been given data that we need to evaluate the flow rate across different section of the pipeline that transports the water. The pipeline consists of several sections with varying diameters and the pressure drops. Here the goal is to determine if the flow rate in each section is within an acceptable range and the acceptable range provided is between 10 lit/s to 50 lit per second. So some of the parameters are given for the each section. Let us first define all the parameters in the format of variables. So here as you can see the target flow rate at the lower side being 10 the target flow rate at the maximum acceptable range that is 50. The pipe diameters are given in the list format that is 0.05.18 and 07. Same way the pressure drops are given for the same section that is 300 500 400 and 350. The pipe length given being the 100 m and the frictional factor is given to be 0.02 and it is assumed to be constant. Now the further data given is we need to use the Darcy waste base equation to calculate the fluid velocity. Next we need to calculate the flow rate and again we need to print if the flow rate is within the acceptable range or not. That means if it is low, normal or high. Now for the conversion purpose also we have been given data that we will use the conversion factor of 1,000 to convert cubic m/s to L/ second but being in the field of mechanical engineering we again must need to have the knowledge of unit conversion based on the need. It is not necessary that in every programs the same details will be given. Now we know that to calculate the flow rate through each section we need to iterate through each section and for the iteration purpose we are having the concept of loops. So initially let us create for loop and that loop will iterate through each pipe diameter and the pressure drop at specific section. So here the conversion factor we have stored as a variable and next we have started our loop that is we will start with section one for i in range the length being the pipe diameters. So for these four different diameters we have considered the length. Now we will iterate through each diameter and each pressure drop. So diameter equal to pipe diameter of I. I refers to the index position 0 1 2 based on the length provided. Same way the pressure drop at the same section is considered as pressure drops of I from the given list. Next we need to calculate the fluid velocity and the equation for the same is 4 LV²ide by 2 GD. So based on that we need to make V being the major variable and remaining all the variables on the right hand side. So the velocity equal to the equation reframed as pressure drop into diameter divide by 4 into f into pipe length and whole ra to 1x2 that is the 5. Next we need to calculate the flow rate and the equation of flow rate being the area into velocity. Velocity we have already calculated in the previous step and it is stored into the variable named velocity. Then it will multiply with the cross-sectional area. So the equation for the same is also mentioned. Now the answer here obtained is the me cube/s. So we need to convert it into the lit per second. And we may need to use the conversion factor to convert it into the lit per second. So we have mentioned flow rate liter/s equal to flow rate m cube second into conversion factor that is 1,000. It is not mandatory to store the conversion factor into the variable. You may directly mention the same value during the calculation also. Now next we need to check based on the given data if the flow rate is within acceptable range or not. We must need to use the if else statements. So if the flow rate lower side is less than the target flow rate then we will print the data for the specific section as we have used the formatting in our previous question also. And here we will print the final data being the low flow. Same way in al if flow rate at the lower side is greater than the target flow rate at the higher level. So we need to print the final answer to be high flow. And in the else case if both are same. If it is in the given range then we will print the normal flow. And after getting any of the answer we will go to the next section. So to increase the section we will consider to be the section plus equal to 1. So using this concept our program will go through each diameter each pressure drop then it will calculate the velocity flow rate and it will check if the data is available within the acceptable range or not. Run the program to check the output. So as you can see at the section one flow rate we obtained is 2.69 lit/s and it is the low flow. Same way you may read the values for the multiple sections also. And if there are more number of sections then you can also include in the given list. So this combination of loop and the conditional statement is very much helpful to come to the conclusion for some of the complex problems and to sort it out in a very simple way. I hope these examples have not only enhanced your understanding of Python programming but also sparked ideas on how to apply these concepts in your engineering work. Remember the true power of programming lies in its ability to solve problems and save the time. I suggest you all to keep experimenting, keep learning and let Python simplify your engineering challenges. See you all in the next session. Hello everyone and welcome. Today I want to discuss about an incredible tool that can make learning and mastering conditional and loop statements lot easier that is jet GPT. We have already used the chat GPT in our previous module also to understand some of the primary concepts. As we dive deeper into the programming concepts especially in Python understanding how to use if statements, for loops and while loops effectively is crucial. These structures form the foundation of logic and repetition in any program. But sometimes figuring out how to structure your conditions or loops for a specific problem can feel difficult. This is where Jet GPT can help. Whether you are stuck on a syntax, need an example for a mechanical engineering problem or want clarification on a complex concept, Jet GPT is essential tool. You can ask for explanations, generate examples, debug your code and explore advanced use cases also. You may challenge yourself with complex scenarios and let Jet GPT guide you step by step in that manner also. So JGPT is not just a source of answers, but it's a companion in your learning journey, helping you think logically and apply concepts to real world problems. So as you work through your conditional and loop statements, don't hesitate to reach out to chat GPT for assistance. Let's use this powerful tool to make your programming journey smoother, faster, and more engaging. Go through some of the important prompts that may be useful to understand how to provide the prompt to chat GPT to get the effective answers. So these are list of some of the important prompts that you may use. Again you may modify this prompt, update this prompt or provide a new prompt based on your requirements. Let us go to Jet GPT to understand how Jed GPT will provide the answers to our provided prompts. Suppose I want to understand break and continue statement in and its use in the context of mechanical engineering. So we may ask the chat GPT also explained use of break and continue statement in mechanical engineering context using Python. Hit enter. So you may see that it will give you the basic information and the idea where you may use this specific tool. So it has given the information about the break statement. Then one example same way the information about the continue statement and the example related to the continue statement and at last it has provided the summary. Now suppose you want to understand the syntax of nested for loop using example. So again you may provide the same prompt explain syntax of nested let us say while loop with example and hit enter. So here you can see that it has provided the syntax then example related to the multiplication table which we have already seen in the context of for loop. Suppose if you want to have the different example. So again you may ask the chat GPT please provide different example. So we will ask provide different example in context of mechanical engineering. So here you can see that the jet GPT is provided the scenario considering the pressure test simulation for the multiple walls. So here it has provided some of the data calculations and the explanations for the code and the expected output also. So I hope you got the idea how this tool is very much helpful to gain more knowledge and more insights in depth in important topics of Python. So remember learning programming is a process and sometimes we all hit a roadblocks but with tools like Jet GPT you have a powerful resource at your fingertips whether it's refining your code gaining a better understanding of concepts or working through challenging examples that GPT can provide the support you need to succeed. The more you practice and experiment the better you will become at solving complex problem with the knowledge you have in Python. Thank you again and I wish you the best of luck in the practice of programming. Keep exploring, keep coding and remember the Jet GPT is always here to assist you. Hello everyone, welcome to the module 3 that is functions and modules. If programming is like building a machine, functions are the individual tools you use to assemble and operate it. They help you to break down complex problems into smaller, manageable pieces, making your code efficient, reusable, and easier to understand. We will start by understanding what functions are, why they are so crucial, and how they empower us to write clean and organized code. From simple mathematical operations to real world engineering problems, you will see how functions can handle everything. After mastering functions, we will explore modules which are like pre-built toolkits in Python. Imagine having an entire library of solutions ready to use for your task. This is what modules offer. Whether it's performing complex mathematical calculations, working with data, or solving engineering problems, Python modules make it all possible with just a few lines of code. By the end of this module, you will not only be able to create your own functions, but also utilize powerful Python modules to tackle challenges in mechanical engineering and beyond. So let's gear up and get started with the functions and modules your building blocks for efficient and professional programming. Let's start by imagining these. You are working on a complex problem in mechanical engineering. Perhaps designing a simulation for stress analysis or fluid flow. The problem is large with multiple repetitive calculations and steps. Now wouldn't it be great if you could simplify this task by organizing your code into smaller reusable components? Well, that's exactly where functions come into play. Functions are the backbone of modular programming in Python. A function is essentially a block of organized, reusable code designed to perform specific task. Instead of writing the same code multiple times, you can define a function once and reuse it as needed. This not only saves time and effort, but also makes your program cleaner, more readable, and easier to debug. functions are particularly important in engineering applications. Whether you are performing calculations like determining stress or strain, automating data analysis or solving equations, functions let you encapsulate logic into reusable pieces. This means you can focus on solving the bigger problem rather than worrying about the repetitive task. So let us discuss about the syntax of a function. How we can create a function in Python language. So as you can see on the screen in Python creating a function starts with the defaf keyword followed by the function name and parentheses for the inputs and at last colon. Inside the function you may write the logic you want to execute but you need to keep in mind that the indentation is important and if needed the function can also return the value or result. So in short input values to function are known as the arguments or parameters and output of function is referred as return values. Let us take an example to create a function and use the same in the Python language. So for that go to the VS code here. As you can see we want to create one function named gaze out and the requirement of that function is to greet the person that is the hello learners. So to create that function first we will use the def that is def then function name it is gazo then parenthesis and in these we do not require any argument or parameters. So these parentheses are kept empty. Then after colon symbol is provided and within that whatever data is required in the function that all will be returned after the colon but the indentation is mandator. So here we have mentioned print hello learners. After creating the function the major important part is to call that function means to use that function such that we will get the output. So to call that function removing indentation in the further lines we need to type the function name then after parenthesis and within parenthesis if arguments are provided then same type of arguments are needed in the parenthesis and if no arguments are provided then same way during function calling no arguments are needed. After calling the function if any further code is required we may also write. So to just get the clarity if function is over or not after calling the function we have mentioned the print statement saying we are outside the function. Now run the program to check the output. So here as you can see due to this g how line. Once this code of block gets executed first function is executed indicating hello learners. After completion of the function, next line will get executed and it will print outside the function. So the same thing you can see in the terminal also. Now you can reuse this function as many number of times as possible based on requirement also. So we may say there are so many benefits of using functions. Some of them are we need to just write the code once and we may use it multiple times. There is also possibility of breaking down large problems into smaller for the logical part due to the concept of the function. The programs becomes more structured and easier to follow. The creation of functions are also helpful for the easy debugging of the code. So fixing an issue in a function automatically corrects it wherever the function is used. Let us again come back to the slides. Now we will take another example also. Here you can see that we have provided the function name calculate rectangle area. The def is already mentioned and within round brackets two arguments are provided length, width. Now the objective is to calculate the area. So after colon within the function we are calculating the area area equal to length into width. And if you want to store this answer into the method then we may use the return statement also. So this return keyword is used to store the output into the method name. So here calculated area will be returned to the given function and that will be our output. Here you can see that the return statement should be the last statement for any of the function. Now to run that we require the two argument that is length equal to 5, width equal to 3. To calculate the area we will call the function and we want to store that answer. So area equal to calculate rectangle area and within parenthesis we will provide the two arguments needed. So here we have passed the variables L comma W. Finally we have printed our answer using the proper formatting options. So here again you can see that this function can now be utilized anywhere in the program and it will perform the same. So with this session I think you got the idea what is the function is how we may use the function. With this session, I hope that you got the idea how to create a specific function and how to call that function. We will discuss in detail about the functions and its usage in our further session. Hello and welcome. In this session, we will be diving deeper into two key components of Python functions that are absolutely crucial to understand arguments and return types. So, let's start with the arguments. Arguments are like the inputs you provide to a function. When you create a function, you often want it to work on a specific data. That's where arguments come into play. They allow you to pass values into a function so that it can perform its task on those values. For example, imagine you are calculating the area of circle. Instead of hard- coding the radius, you can create a function where the radius is an argument. When you call the function, you provide the value of the radius. The function calculates the area based on that value. This makes your function more flexible and reusable. In Python, you define arguments inside the parenthesis of a function. You can have as many arguments as you need. You can even set default values. So if the user doesn't provide an input, the function uses the default value. So to understand the part of arguments, let us go to the VS code where we have already created one program. Here you can see that we have created one function with the keyword dev. The function name is calculate stress. And here to calculate the stress two arguments are required that is force and area. So as you can see the first argument provided is force and the second argument is area. And here you can see that the argument area is provided with the default values. So if user do not provide any other value then the default value for the area will be considered to be 50. After providing the arguments colon symbol is provided and within that the required operation is performed. So within these parentheses the arguments are provided and in future while calling the function we will provide the value of force and the area based on requirement. Now let's move on to the return type. Let us again go back to the slide. Now when a function complete its task, it often needs to send the result back to the part of the program that called it. This is done using the return statement. So think of it as the output of the function. For instance, consider the first example. Let's consider the area of circle that we want to calculate. After calculating the area, function can return the value so that you can use it elsewhere in your program. Maybe you can print it, save it to a file or use it for the another calculation. So here is why arguments and the return types are so important. The arguments allow you to make your function dynamic. Instead of working with fixed values, your function can handle variety of inputs. Written types allow your function to send results back to the main program making them highly versatile and enabling complex workflows for better programming. So if we summarize these arguments are the inputs that you give to the function and the return types are the outputs you get from the function. Let us again go back to our program. So here you can see that after colon we have calculated the stress that is equal to force divide by area and we want to return the value of stress to this function. So as you can see the keyword required is written and then after we will provide the value that we want to return. In our case we want to return the stress. So we have mentioned stress. Now to call that function we need to provide the two arguments. In our case we have provided the fixed area that is 50. So we need to provide the value of force. So for that we have defined the value of force that is equal to,000. Now we need to store the value of stress that has been calculated using the formula. So we have stored it into the variable named stress with default area equal to we are calling the function calculate stress and as you can see the default cross-sectional area is also provided. So we need to just provide one argument that is the force. So calculate stress within bracket we have provided the argument to be force. So the value of force that is 1,000 will pass into this function. Area will be considered to be the 50. Now the stress will be calculated that is force divide by area and the answer for that will be returned back to that function. This function stores the answer into the variable named stress with default area. Then after we have printed the answer in a specific format. Same way you can see that if we want to change the area then we have stored it into the variable let us say custom area that is equal to 75. Again we are calculating the stress but here we want to change the default value of area. So that calculate stress function is called by passing the two argument. First one is force and second one is custom area. So based on these two provided values again function calculates the stress and the value of stress is returned back to our function and this value is stored into the variable named stress with custom area. Finally after calculating the stress again the answer is printed with a specific format. Let us run the program to check the output. So here you can see that the stress with default area being 20 megapascal and stress with custom area being 13.33 mega pascal. So I hope you got the idea how to make use of these functions and the use of arguments and the return parameters to get the output based on the requirement. To understand it properly again let us consider the second example. So here you can see that we want to check for the safety and based on the stress value and the safety limit provided we want to check if the part is safe with the stress level or part is unsafe with the stress level. So for that we have defined the check safety function. It is having the two arguments stress safe limit. Within that function we have calculated if stress is less than equal to safe limit we will print the part is safe. Else we will print the part is unsafe. So for that we have considered the two inputs that is trace equal to 180 and the safe limit being the 200. Now to check if the part is safe or not we need to provide these two inputs into the function and to call that function we can simply write the name of function that is check safety. Within that we will provide the two arguments. First being the stress and second being the safe limit. Here keep in mind that you need to provide the input in the same sequence as we have defined in the function syntax. So first we have provided stress so we need to provide the value of stress only. Second we have provided the value of safe limit. So we need to provide the value of safe limit only. So the sequence in which we are providing the input is also important to get the proper output from the function. Now here we can see that 180 is less than or equal to 200. So the answer is true. So we will get the output. The part is safe with a stress level of 180 megapascal. So again run the program to check the output. So here you can see that the part is safe with a stress level of 180 megapascal. So using these case of functions you can convert your bigger program into a smaller sections and using that functions you can easily manage the different operations of your program. I hope with this session you got the idea how to create a function, how to provide arguments and get the return type based on the requirement. Looking forward to see you all in our further session. Till then thank you. Hello everyone and welcome back. Today we will discuss about very versatile concept in Python functions that is arbitrary argument. There are times when you might not know in advance how many arguments a function will need to handle it. That's where arbitrary arguments come into play. They allow your functions to accept a variable number of inputs making them adaptable and powerful in real world scenarios. In this session, we will explore how to use arbitrary arguments, their syntax, and how they can be applied to handle dynamic data inputs effectively. So for that, let's get started with the syntax of arbitrary positional arguments. So here as you can see star args that syntax that part collects all positional arguments into a tuple. You can iterate through arcs to access individual values. So to define arbitrary positional arguments we need to write star args within the parenthesis of the function. So if we consider the syntax as you can see on the screen first we will provide def then function name and within parenthesis we will provide star args. Now to iterate through all the possible arguments you may use the for loop. So as you can see for arg in args that is for each element in args we can perform different operations based on the requirement. If you want to print the argument you can simply print the argument. Other than this you may perform any mathematical operations or the required operations based on your need within this function. Now to call this function we may need to write function name. Then within bracket we may pass any number of arguments. That means we may pass one argument, two argument, three argument or any variable number of argument. So that is the major advantage of using arbitrary positional arguments. To understand its use, let us go to the VS code and run one program. So here you can see that we have created one specific function with name calculate total load. Within that we have provided the variable argument that is star loads. So it represents that we may provide the any number of load based on the requirement. Within that function our objective is to find sum of loads. So we have stored its answer into the variable total load equal to inbuilt function used is sum and within its argument we have provided all the loads that we have passed into the argument of function we have created. After calculating the total load, we have printed the final answer with the specific format. Now to call that function, as you can see, we have provided two different options. First, calculate total load function is called with the three argument. Again, we have also called calculate total load function with the four argument. So you may also pass two, three, four or any number of arguments based on your need. So that is the major advantage of using these arbitrary arguments. Let us run the program to check the output. So here as you can see in the first case total applied load and in the second case total applied load we are getting based on the provided value. So I hope you got the idea how these arbitrary arguments are useful while creating the functions. Let us again go back to the presentation. Now we will understand the syntax for the arbitrary keywords argument and as you can see for that we need to provide two times star symbol and then after the argument name. So here we have provided the keyword arguments. So the syntax for the same is first we will provide def then function name and within parenthesis we will provide star variable or the arbitrary argument name. Now these keyword argument refers to the key value pair only. So for that we may again iterate through each element using the for loop. So for key comma value in keyword asks dot items. items is the inbuilt function that will iterate through each element of key and value and we may print the key and value based on the required format. The advantage we have is that while calling the function we will provide the function name and within bracket we may provide any number of key value pair based on our need. So we may pass 1 2 3 4 or maximum any number of pairs based on requirement while creating these keyword arguments. Again to understand this syntax let us go back to VS code. We have created one function that is def display component properties. We have provided the arbitrary keyword arguments. Within this function we have printed component properties. We want to print its key and value based on the input data. So for key comm, value in kox dot items. Within that we want to print key and value. Now how we can access this combination. So for that as you can see we have called this function display component properties. We are providing the multiple key value combinations that is name gear material steel diameter 200 mm and the weight being the 15 kg. Same way suppose if you want to change the key value combination then again it is possible. So in second function you can see that we have provided name soft length 1.5 m diameter 50 mm and the material to be the aluminum. Now how it will give us the output to check that let us run the program. So here you can see that the key is name and the value is gear. Then same way material and steel diameter is 200 mm and weight is 15 kg. So there are multiple key value combinations are provided using the equal to operator and all are separated by the comma and any number of argument any type of argument if you provide that will be executed based on the created function. So this keyword argument is also very much helpful to collect all keyword arguments into a dictionary. You can iterate through kbox dot items to access key value pairs. So let us go back to presentation to again understand it in detail. So here you can see that K works that is keyword arguments collect all keyword arguments into a dictionary and you can iterate through each item using the inbuilt function that is items with the parenthesis to access key value pairs. We have already seen in the example that how to utilize this concept to execute the arbitrary keyword argument. So why to use these arbitrary arguments? So you can see that you don't have to you don't have to specify the number of loads when defining the function. That means you are having the flexibility to provide the number of loads based on your requirement and the program will give you output dynamically based on your inputs. It can also handle both small and large data sets without any modification. So with this discussion of arbitrary positional arguments and the arbitrary keyword arguments, I hope you got the idea how to take advantage of these arbitrary positional and keyword arguments during creation of functions and utilize it with the maximum possible outcomes. Looking forward to see you all in our further sessions. Till then thank you. Hello everyone. Today we are diving into an essential concept in Python programming that is variable scope. This is critical topic that determines how and where variables can be accessed or modified in your code. Whether you are writing a simple programs or complex systems, understanding variable scope will help you avoid errors and write clean, efficient and predictable code. So let's get started with the variable scope. So the variable scope refers to the region in a program where a variable is accessible. In Python, variables are not all treated equally. They depend on where and how they are defined. Knowing the scope help us understand where a variable exist and where it do not exist. Python defines four types of variable scope. Local scope, enclosing scope, global scope and built-in scope. These scopes are collectively known as legb rule that is leb rule which stands for local enclosing global and built-in scope. So let us have a brief discussion about the logic of different scope. So the local scope. So if the variable declared inside a function belong to the local scope, they can only be accessed within that function only. Once the function execution is complete, these variables are automatically discarded. When variables defined in an enclosing function that is function inside another function, these are in the enclosing scope. These variables are accessible to the inner function but they are not global. If variables are declared outside any function or block they all are belong to the global scope and these variables are accessible throughout the program unless they are shadowed by the local variables and Python has a set of built-in functions and keywords such as the len range that we are using in our for loop also which are always available unless overridden. Now to understand how these variables can be accessed and where they can be accessed, let us go to the VS code with one program. We will understand the area of different scopes. So here in the program as you can see one variable is defined global factor equal to 1.5 and this variable is defined outside the function but inside the program. So this variable can be accessed throughout the program from first line to the last line. So this variable is known as the global variable. Next we have created the calculate torque function. It is having two arguments and within these one variable is created pi equal to 3.1415. So this variable is declared inside the function. So it is known as the local variable and this variable can be accessed up to the limit of this calculator function only and this one is limited up to this specific area that is from line number four to 18. But after line number 18 this pi named variable gets automatically discarded. Now within this calculate torque function you are also seeing another function is created that is define adjust torque. So within this function one variable is created adjustment factor. So adjustment factor variable is created inside the function. The location of these variable is function inside a function. So this variable is known as the enclosing variable and the scope of this variable is up to these defined function only that is adjustment torque. Next again torque variable is created. Adjusted torque variable is created. All these variables are created within these defined calculate torque function only. So the scope of that function being the local they are limited up to these defined function only. After that you will see the print function. So we are every time printing our required data using this print function. So this print is inbuilt function and this can be accessed anywhere in any of the program based on the requirement. So here you can see that we have used global variable, local variable, enclosing variable and built-in functions also to show you how these variables can be accessed within that scope. So in current section all the variables are managed very well and utilized very well. So we are not getting any error. So let us run the program. Here we need to input the applied force. So let us say that is 1,000. We will provide the radius in meter that is being 20. So the adjusted torque is calculated based on the provided value. So we are not getting any error. But now suppose if we are accessing these variable outside the scope then we will 100% get the error. So to understand that let us see this pi variable is having local scope up to this defined function only. Now suppose if I am accessing after the line number 18 I want to print variable pi. So here you can see that it is representing the error that is pi is not defined and it is due to the reason that after completion of these function automatically pi variable gets discarded. So knowing the variable scope help us to understand where this variable exist and where we can access this variable based on the need. So I hope you got the idea how the different variables that we can provide into the program and how we can make use of that variables based on our requirement. Hello everyone and welcome to today's session. In this lecture we will explore global variables in Python. A fundamental concept that plays a crucial role in programming when dealing with the data across multiple functions. By the end of this session, you will have a solid understanding of what global variables are, when to use them, and how they function within Python scope hierarchy. A global variable is a variable that is defined outside of any function, block or class. Unlike local variables which are confined to the function, they are defined in global variables. They can be accessed and modified by any part of the program provided they met certain conditions. They are often used when we want to share data across multiple functions without passing it explicitly as arguments. For example, in real world applications, a global variable might store a configuration setting or a constant value that is relevant throughout the program. So imagine you are working on a mechanical simulation. You have a constant safety factor that needs to be applied across different calculations such as stress analysis, torque calculations, and thermal performance evolutions. Instead of defining the safety factor in every single function, you can declare it as a global variable and access it anywhere in the program. Here key points to remember about global variables are global variables are accessible anywhere in the program. They simplify code by reducing the need for repetitive arguments but they should be used sparingly. Too many global variables can make your code harder to debug and maintain. If you need to modify global variable inside a function, you must explicitly declare it using the global keyword. So these global variables are incredibly useful when a value is truly universal across all the functions. And passing the value repeatedly as an argument would make the program unnecessarily verbose. To understand the use of global keyword, let us go to the VS code. In this program, as you can see, we have provided global variable safety factor equal to 1.5. Now we want to use this safety factor variable inside both the function. So it is better that we define the safety factor to be the global and for that within function we will mention global then variable name. We are using these now variable torque equal to force into radius into safety factor. Due to use of these keyword as you can see we are reducing the number of arguments required during this calculation also. Same way in the calculate stress function we are providing the global safety factor so it can be accessed easily as a global variable. Now to run this program we require different arguments that is force radius load and area during the call of function as you can see we are just passing two arguments force and radius and due to the declaration of the global variable safety factor can be accessed easily throughout the program. So it will access the value of safety factor to be the 1.5 in both the cases and it will give us the output for the calculation of torque and stress. Let us run the program to check the output. So here you can see that we are getting the value of torque as well as stress. So I hope you got the idea how to use this global keyword to access the global variable throughout the program. But the one important thing to keep in mind is overusing the global keyword can lead to the unexpected bugs or confusing dependencies. So the key is to strike a balance. Use global variables for constants or configuration data but avoid them for intermediate calculations or temporary values. So in conclusion, global variables are like shared tools in workshop. They are convenient and powerful, but they should be handled carefully to maintain order and efficiency in your code. With this knowledge, you are now better equipped to write Python programs that are efficient and easy to manage. So make use of all the concepts that we have utilized till now that is the defining functions, scope of variables and use of global keyword and it will help you to prepare more solid and understandable code. We will dive deeper into the Python programming in our further session with the concept of modules. Hello everyone and welcome to today's session on Python modules. Today we will dive deep into one of Python's most powerful features that is modules. Whether you are working on a simple script or a large project, modules are essential for creating organized, efficient and reusable code. By the end of this session, you will understand what modules are, how to use them, and why they are critical in Python programming. A module in a Python is simply a file that contains a Python code and it can include functions, variables, classes, and even runnable code. Modules allow us to break down complex programs into a smaller manageable pieces making the code more readable and reusable and essentially they enable us to write a modular code. So why do we use modules? So once a module is created it can be used across multiple programs. Code can be divided into logical parts improving readability and maintainability. In large teams, the different members can work on a separate modules and the Python comes with a rich library of built-in modules and you can also install that third party modules based on your need. So there are different types of Python modules are available. First one is built-in modules. So they are pre-installed with Python such as the math, random and OS module. Other than that there are many different modules are available. Second is userdefined modules. So these modules you can create yourself to organize your code. And the third is third party modules. So these modules created by others which can be installed using pip such as numpy, pandas and met.ly. These are some of the examples. But other than this there are so many different third party modules are available. So in a simple terms userdefined modules are nothing but the py file generated by us and we can access the data of these files in other different programs also based on requirement. How to access that data we will understand in detail in our further sessions. Let us just have a discussion how to use these built-in modules in our programs. For that let us go to the VS code. Here we want to use the math module available into the system and for that to access any of the inbuilt module we need to use the import statement. First we will write the import then after module name. So we want to access the math module. So we have mentioned import math. Now we want to access the variable available pi within the math module. So for that we can access the pi variable using the dot operator. So to calculate the area as you can see we have mentioned math.py so it will access the pi variable available within math module and accordingly the equation is provided and the answer is printed based on the required format. So using the first statement import math you can see that it will import the entire math module and you can access any of the properties available within the math module. Second approach to import the module is we can import a specific functions from the math module. So suppose we want to access variable pi and the square root function from the math module. So we may write from math import pi, square root that is sqrt which is inbuilt syntax. Same way you may also import multiple variables or functions based on your need and that all should be separated by comma. So from this second statement, it will only import the given variables and the functions in the import statement. The third option to import the math module is you can import the math module with the allies also. That means you can import the math module with the different name. So suppose I want to import math module as name M then we may write import math as M. So now we may access all the elements of math module by using the name m. So let us say I want to find the square root of number 36. So we may directly print the answer print. Now to access the square root function it is available within the math class. We have imported the math as m. So we may write m dot square root and within parenthesis we will provide the value that is 36. Now to print specific format let us write square root is m dot square roo<unk>36. So now we can access all the properties of math module using these m allies. Another possible approach to import the built-in module is we can import all functions from the given module and for that we may write from math import star. So this star refers to all the functions available within the math module. So these are different approaches available to import the built-in module based on our requirement and you may use the same approach to import userdefined modules as well as third party modules. Let us run the program to check the output. So here you can see that based on the data provided we are getting the different output. So this means the syntax we have provided over here is 100% valid and we may use these different import approaches to use the built-in modules. There are so many different in-built modules are available and we will discuss about some of the important built-in modules and their use in our further session. Hello everyone and welcome back to our Python for mechanical engineering series. Today we are diving into an exciting and practical topic that is built-in Python modules relevant to our mechanical engineering. Python is renovant for its extensive library of built-in modules that can save us time and efforts by providing pre-written readytouse functions for various task. As a mechanical engineer, you might find yourself dealing with task like numerical analysis, plotting data, handling complex mathematical calculations, and even working with the data files. Instead of writing everything from scratch, Python's built-in modules empower us to focus on solving engineering problems more efficiently. In this session, we will discuss the most useful built-in modules for mechanical engineers, their applications, and where these may be useful based on our need. So, let's explore the tools Python provide to enhance our productivity and problem solving capabilities in the world of mechanical engineering. So, here the list of built-in Python modules are available that may be relevant to the mechanical engineering. First is the math module. So it provides access to mathematical functions like trigonometric calculations, logarithmic, square roots and constants like pi and many more. So this is useful while calculating stress, strains or flow rates using the different formulas. Second is statistics and it provides functions to perform statistical operations like mean, median, variance and standard deviation and it is useful in analyzing experimental data or quality control metrics. Third is random module and it generates random numbers for the simulation purpose. So it may be useful while simulating material failure probabilities or testing designs under random conditions. Fourth is the time module and it provides functions to work with time related operations and it is useful for tracking performance or runtime analysis of different processes. Next is OS module and it enables us to interact with the operating system. So it may be helpful for automatic file handling for analysis of reports or simulation of the files. Next is the CSV module and it simplifies reading from and writing to the CSV file. So it is useful for processing experimental data or importing data sets for the further analysis. Next is JSON and it handles JSON data for configuration and the structured data and it is useful for exchanging configuration settings for the simulation purpose. The next is ITL tools and it provides tools for working with the iterators and generating combinations or permutations and it is useful while analyzing multiple design scenarios or parameter combinations. Next is collections and it provides specialized container data types such as DQ and counter and many more and it is useful while optimizing inventory management in manufacturing or counting defect occurrences. We are just listing here some of the important usage only but there may be many different usage you may find based on your need. The next module is CIS module and it can access system specific parameters and the functions and it is useful for handling command line arguments for custom simulation inputs. The next modules are the third party modules that are technically external but often considered essential for the programming purpose. So the numpy module performs advanced mathematical and array operation and they are useful for handling large numerical computations in finite element analysis. The next is metplot lib and it creates 2D plots and visualization and it is useful for visualizing stress distribution thermal profiles or the dynamic responses. The next one is scypi and it provides advanced scientific and engineering mathematical tools and it is useful for solving differential equations, optimization problems and for your transformations also. And the last one is the pandas library and it is useful for handling tabular data for analysis and manipulation and it is useful for managing large data sets from experiments or simulations. So these are the different Python modules that may be very much helpful for creating the mechanical engineering programs. In the upcoming sessions, we will explore some of these modules in depth with practical examples tailored for mechanical engineers. We will demonstrate how they can be applied to solve real world engineering problems, automate task and simplify complex computations. Remember these modules are your tools. The better you understand their capabilities, the more efficiently you can work in your field. So let's work with these and make Python a powerful companion in your mechanical engineering journey. Hello everyone. In this session we will discuss how to make use of userdefined modules with the example. Let us go to the VS code to understand it with the example. Here you can see that we have created one file mechanics.py and it is having three data two functions and one variable. First function is def calculate stress which will calculate the stress and return the value based on the two input force and area. Second is calculate torque. It is having again two arguments and it will return the final calculated torque to the defined function. And the third is density is provided that is material density equal to 7850. So here you can see that these generated file mechanics. py is the userdefined module and we may use this module in t we may use this module in the another file also based on our need but for that the import statement is required as we have discussed in our previous sessions. So let us say we want to access this mechanics module into this other file that is main. Now to access this module the foremost important statement is import statement. If we want to import all the properties of the mechanics module, we will write import then module name. And in our case, the module name is mechanics. Then after we have provided the two variables force and area. Now to calculate the stress, we can call the function available within the calculate stress. We can call the function available within mechanics module that is the calculate stress. And for that we will write mechanics dot calculate stress. And we need to provide the two argument and it will calculate the stress based on the given data and the answer is stored into the variable named stress. And then after the answer is printed based on the required format. Second, as we have already seen we can import the specific functionality of these module also. So for that we will write from mechanics import calculate torque. So it will only import the property calculate torque and remaining will remain hidden. So after importing the same we may calculate the torque by providing the different data. The third option is we can import the mechanics module with the different allies also and for that we may write import mechanics as mac. So to access now different properties we may use this name mac. So suppose we want to access the density. So density equal to mac dot it is having the variable material density. And the last one is we may import all the properties of the mechanics module. And for that we may write from mechanics import start. So it will import all the functions and variables from this mechanics module. And again we may use any of the functionalities based on our requirement. So I hope you got the idea. The methodology will remain same. It may be the built-in module, userdefined module or the third party module. We need to first import the required module and then based on the import statement we may access the different variables or the properties of the imported module. Let us run the program to just check the output. So here you can see that we are getting the output based on the required input. So I hope you got the idea how we may use the userdefined function and we may import that function into the different programs also. So we may reuse the code based on our requirement. In our next session we will discuss about how to use JG GPT for function design and the code modularity. So looking forward to see you all in our further session. Till then thank you. Hello everyone and welcome to another session where we will explore the exciting applications of Python in programming. So today we are going to focus on two critical aspect of writing effective and maintainable code that is function design and code modularity. These are essential concept not just for Python but for programming in general especially when working on a large scale projects or solving complex problems. Have you ever faced a situation where your code became too long, difficult to understand or hard to debug? Or maybe you have struggled to reuse a piece of code across multiple projects. Well, this is where functions and modularity come into play. Functions allow us to break down large program into a smaller reusable block of code making it easier to read, debug and maintain. And about this we have already discussed in detail in our previous session. On the other hand, code modularity help us to organize our programs into a logical independent parts making collaborations and scaling up projects with much more manageable way. And here is the best part. The chat GPT can assist you in understanding these concepts, designing functions and creating a modular code for any domain including mechanical engineering, data science or even automation. Whether you are looking to improve your existing code, create efficient algorithms or just explore best practices, Jet GBT is here to guide you when working with Python. Clear prompts can help us uncover various features of the language including functions, variable scope, modular programming and applications in specific domain like mechanical engineering. Today we will discuss well-crafted prompts and example that not only clarify the concepts but also connect them to the real world scenarios. So here are some of the important prompts that you may use to understand some of the important topics of the Python using Jet GPT. You may use these prompts also or you may create your own prompts also based on your need. Now to understand this prompt and its outcome. Let us go to the chat GPT. Suppose we want to understand how to create a function without a return type. So for that uh we may provide the prompt how to create a function without a return type and as we want to understand it with the language Python. So we will provide using Python and hit enter. So here you can see that the chat GPT has provided one simple outcome that shows how to create a function without a return type and one example is also provided. It has also provided how to call the same function. Next, suppose we want to understand the variable scope with the example. So we may provide the prompt explain variable scope with examples including all possible types. Here you can see that Jet GPT is providing different examples for the different scope of variables and you may explore all different scope using the same example that has been given by the state GPT. So with the list of example it has also provided some of the important key points that define the difference between the different scope of variables. Suppose we want to understand the scope of these variables in context of mechanical engineering. So we may also provide the prompt explain variable scope in context of mechanical engineering and its use. So here you can see that now the JGPT is providing the examples in context of the mechanical engineering so that you may relate it more in a clear manner. With this, I hope that with Jet GPD's assistance, you can master each of these aspect by practicing with a specific and actionable prompts. This way, you will not only learn the theoretical concepts, but also gain hands-on experience with practical coding challenges. Hello everyone and welcome to module four where we'll be diving into numerical computations with NumPy. Numpai is one of the most widely used libraries in Python and it is fundamental tool for any engineer, data scientist or researcher working with the large data sets, mathematical computations or scientific applications. Whether you are solving engineering problems, analyzing experimental data or doing any kind of numerical computation, NumPy is the go-to solution for handling arrays and matrix efficiently. In this module, we will understand the core concepts of numpy including its array structure and data types. We will also learn how to perform element wise operations and linear algebraic operations using numpy function. We will explore the random module in numpy to generate random data for simulation and testing. We will also perform matrix manipulations and tackle problems in mechanical engineering like stress train analysis and fluid dynamics all with the power of numpy. By the end of this module, you will not only be able to perform complex numerical operations but also enhance the performance and efficiency of your code with the help of NumPy. So all right, let's get started with the first steps of working with NumPy. Before we jump into core functionality, we need to ensure that NumPy is installed. We may need to be able to check its version and learn how to use it in our programs. To begin, we need to install NumPy on our system. If you haven't installed it already, you can use the Python package manager pip. You can install numpy by running the command in your terminal or command prompt that is pip install numpy. To understand this, let us open terminal or command prompt. In my case, I am opening the terminal. Now to install numpy, you need to type pip install numpy and hit enter. In my case, as you can see, I have already installed numpy. So it is showing that there is a new release of keep available. In your case if numpy is not installed then it will start installing the numpy. But make sure you are having the working internet connection to install this numpy library. To upgrade numpy you need to type pip install d-upgrade pip and as you can see it will start updating the new numpy version available in the system. After installation of the numpy you can check the numpy version also. For that you need to type python- c then import numpy and print numpy-c version_. So this is the line of code you need to write to check the numpy version also. And after installing the numpy version, we need to import it into our python program. And the standard way of importing numpy is as we need to type as a first line import numpy or you can use numpy other name also as an alias. For that you need to type import numpy as other name that you want. In my case I have mentioned import numpy as np. So by using np as an alias we can refer to numpy functions in much shorter way which keeps our code clean and readable. One of the main features of numpy is its array functionality. We can create one-dimensional array using np dot array function. So to use that function the first statement needed is the import statement. So we have mentioned import numpy as np. To create a one-dimensional array we need to store it into one variable. Let us say the variable is array equal to np dot array. Within round bracket we will provide our 1D array. So we need to indicate 1D array using the list function using the square brackets. So within square brackets in the array argument we have mentioned 1 2 3 4 5. So here we are creating a 1D array with the values 1 2 3 4 and 5. Numpy arrays are much more efficient than Python list especially when you are dealing with the large data sets or need to perform complex mathematical operation. And finally to print that array you can type print and within that you can pass the variable in which the array is stored. Let's combine everything we have learned so far into our simple program. We will install numpy, import it, create 1D array and perform basic operation. So let us go to VS code to execute the program. So here just for the clarity purpose one file is created and the steps are mentioned that we need to follow. The first statement is we need to import numpy. So for that we need to type import numpy as np. Second to create a one-dimensional array we need to store it into one variable that is array equal to the function we will use that is array which is available within np. So we will write np dot array and within its round bracket we will provide our elements that are required to create a array. So we will type array equal to np dot array within square bracket 10 20 30 40 and [clears throat] 50. So using this line we can create a 1D array with the values 10 to 15. Now then we perform a simple mathematical operation by multiplying each element of the array by two and this operation is applied to each element element wise which is a key feature of by arrays. So for that we have mentioned result equal to array multiplied by two. So the entire result will be stored into the variable result and the each element of array will be multiplied by two. Finally we print both the original and modified [clears throat] arrays. So in first we have printed the array and in second we have printed the result. Let us run the program to check if we are getting the output or not. So here as the output you can see that the original array is 10 to 50 and the modified array is 2200. As we have multiplied the array by two. So each element of that array also gets multiplied by two. Here [clears throat] keep in mind that this import statement is most important if we are removing that import statement. Then we are not able to access all the functionalities of that numpy library. This is just a basic introduction to working with numpy arrays. As we move forward we will explore more advanced features and operations such as slicing, resetting arrays and perform complex mathematical operations. With this foundational knowledge, you can now start integrating numpy into your engineering problems. So let's move ahead and learn how to perform more complex numerical operations with numpy using the concept of arrays in our further session. Hello and welcome everyone. In this session, let's explore different ways to create arrays in numpy. These methods are incredibly useful when initializing arrays for computation in engineering, data analysis or simulation. There are different functions are available to create array in numpy and the first one is zeros within which we need to pass two arguments save data type required for the zeros and again the data type provided that may be the optional. So if you needed you may provide the data type here save defines that we will provide the tpple defining the dimensions of the array and d type will be the data type and the default value for that will be the float. Second is the arrange function and it generates a 1D array of evenly spaced values within a specified range and it's similar to Python's range function but it returns a nump by array. So the syntax for the same is also provided here as an argument. We will provide the starting value. If we have not provided then the default value will be zero. Then we need to provide the stopping value and it is excluded from the calculation. Third, we need to provide the step size and the default value for that is one. And the last one will be the data type of the elements. The next one is the random module available within the numpy and that random module is having the function rand which creates an array of random numbers between 0 and 1 and the numbers are driven from a uniform distribution. So as you can see in the random function we need to provide the multiple values that is d1 comma d2 up to dn which represents the dimensions of the array. The last one is the empty function which is again available within the numpy module and it creates an uninitialized array of specified s. The values in the array are random and depend on the state of the memory. So here again same refers to the tpple defining the array and d type refers to the data type of the array elements and the default value for that is plot. So let us go to the VS code to access all these different functions and create different required arrays. Here one file is created the import statement is mentioned that is import numpy as np. Now the first step is we will create a 3x4 array filled with the zeros. So to create a 3x4 array filled with the zeros we are having the zeros function in the numpy and within which we will provide the 3a 4 in the tuple format. So here as you can see we have stored one array into the np.zeros and within its argument provided the 3a 4. So 3a 4 in the round bracket refers to the tuple and it will create 3x4 array. Next one message is printed and our objective is to print that final array. So let us run the program. So here you can see that the 3x4 array is created and it is having the default value float. So all the values are mentioned in the format of 0. Second suppose we want to create an array from 0 to 20 with a step size of five. So for that we may use the arrange function and as you can see we will use the function np do.range. We'll start from zero ending point or the stopping point will be 20 comma step size will be five and d type if you want to assign we can assign d type equal to any relatable data type from the starting and stopping value. So here it is mentioned d type equal to flo. Next again whatever the array may be created that will be printed using the print function. Let us again run the program. So here you can see that the array with nparrange created and it is having the step of five. So the value is 0.5 point 10 and 15 point. One point you can keep in mind is the ending value that is 20 is excluded from the given range. Third suppose we want to create a 2x3 array with random values. So for that you need to use the random module available within the numpy library. So again we are storing the answer into the array random equal to np dot random within random module random function is available. So rand 2 3. So 2a 3 refers to the tpple and it will represent the 2x3 array. Again whatever random array may be created it will be printed on the screen using this print function. Let us run the program. Here you can see that the 2x3 array is created and it is having the value in the range of 0 to 1. Last suppose we want to create a 2x2 empty array. So for that we need to use the functionality empty and for that we will store the answer array empty equal to np empty. Again we will provide the dimension in the format of tpple 2x2. Then whatever empty array may be created that will be printed on the screen. But here keep in mind that this function creates an uninitialized array of the specified steps of the specified shape and to represent that shape we may use the res functionality also that we will understand in our further session. The values in this array are random and that depends on the state of the memory. So let us run the program and check it. So here you can see that one empty array is created with the value 0 5 10 and 15. Here again take a note that the values in these array are arbitrary and uninitialized. So if we see these zeros function can be used when you need an array initialized with zeros. One can use arrange for creating a range of numbers in a specific pattern. This random function is useful for generating arrays filled with the random values. And this empty function used for creating arrays quickly when you don't need any initialization. So these array creation methods form the foundation for working with numerical data in Python. Start experiment with them to suit your specific needs. I hope you find this content very informative and you are practicing very well to have the idea about these different functionality and how to utilize them based on require. So looking forward to see you all in our further session. Till then thank you. Welcome back everyone. Today we are diving into one of the most important and powerful aspect of numpy that is creation of n-dimensional arrays and it is also known as ND arrays. These arrays are the backbone of numerical computations in Python particularly for engineering scientific research and data analysis. We will explore how to create these arrays from scratch. How to transform basic Python list into multi-dimensional arrays and even how to build complex arrays using specialized numpy functions like zeros, arrange and random. And these functions we have already seen for the one-dimensional array. By the end of this session, you will have a clear understanding of how to manipulate ND arrays for your computational need. So let's get started. Numpy allows the creation of n-dimensional arrays where n can be 1, two or even. These arrays are more efficient than python list because they store data in a contigious block of memory allowing for the faster computation. Now to understand that let us go to the VS code. Suppose our first objective is to create a one-dimensional array. So to use the numpy functionality the first important statement is the import. We have mentioned import numpy as np. Now to create a two-dimensional array we will store that array into one variable and then we will use the functionality np array and within that now using proper square brackets we need to define the two dimensional array. So as you can see we have defined one variable array_2d using np dot array. Now within outer square brackets two again square brackets are provided separated by comma. So here each square bracket within outer square bracket refers to the one-dimensional array. So the value 1 2 3 refers to the one dimension and the value 4 5 6 refers to the second dimension. So let us run the program to check the output how this 2D array can be accessed. So here you can see that the two-dimensional array is created that is 1 2 3 4 5 6 and it is a 2x3 array. Next to create a three-dimensional array as you can see within outer square bracket one inner square bracket within outer square bracket inner square brackets are provided to refer to the two dimension. Same way to refer to the three dimension we need to provide outer bracket for the one dimensional inner square bracket for the two dimension and within that again we will consider another square bracket to refer to the three dimension. So to understand that let us check this content using np dot array within outer square bracket inner square brackets are provided that are highlighted with the blue and within that again two parts are separated with these yellow square bracket and the values are 1 2 3 4. So these inner square brackets refers to the three dimension. Same way comma separated again inner square brackets are provided. So within blue square bracket, yellow square brackets are referred to the three-dimensional data. While accessing the multiple dimensional data, keep in mind you need to have the clear idea about setting the square brackets. Let us run the program to check the output. So here you can see that the three-dimensional array is created with the values 1 2 3 4 5 6 7 8. You can also create a n-dimensional array directly from a nested list in a Python. Each level of nesting corresponds to a dimension of the array. So suppose we want to create a list of list for three-dimensional array. So let us again check the content. We have stored it into the list of list. Now within outer square bracket two inner square brackets are provided and within pink square brackets these blue square brackets are separated. So within three square bracket we are having the value. So it represents the three-dimensional data. So this list of list is nothing but the concept of three-dimensional array only. And to convert that list of list to a three-dimensional array again we need to use the functionality np dot array. So at the bottom as you can see we have created three-dimensional array by converting that list of list and for that np dot array within argument we have passed this variable list of list. So it will create the array from this list of list concept. Let us run the program to check the output. So here you can see that we are getting the three-dimensional data by using the concept of list of list. As we have already discussed in our previous session, the numpy provides built-in functions to create the one-dimensional array. So as well as it provides the functionality for the multi-dimensional arrays. Let us assume that we want to create a 3x3x3 array filled with the zeros. So for that we can use the functionality zeros and for that we can store the answer let us say array_0 the function is np do. dot zeros then within bracket we will provide the dimensions in the tpple format. So that is 3a 3a 3. So it represents three 3 + 3 + 3 array and then we have printed that array. Let us run the program. So here you can see that 3 + 3 array is created having the default values zero and the default data type being the float. Next suppose we want to create a 3 + 4 + 2 matrix with the numbers from 1 to 24 and for that [clears throat] we may use the inbuilt functionality a range and it generates evenly spaced values and can be resaved into n dimensional arrays also. So let us again go to that code and as you can see we have stored the answer into the array arrange. The function is nparange 1, 25. nparrange creates the one-dimensional array from value 1 to 24 and it will be the equally spaced data. Now suppose we want to convert that one-dimensional array and we want to reshape it to the another array. Then we need to use the inbuilt functionality res. So again we have called different function dot resave and within argument we will provide the dimension of the array. So the dimension required is 3a 4 2. So it will create a array having the value 1 to 24 and that value will be resaved into the required 3 + 4 + 2 array. Let us run the program to check the output. So here you can see that at the bottom you will find the output. So it is having the data 3 + 4 + 2 elements. So this is our 3 + 4 + 2 array. So using this reset function one can easily change the shape of the matrix based on the requirement. Now last suppose we want to create a 2 + 3 + 4 array with the random values. So for that we need to use the inbuilt random module available in numpy and we will use the function rend. So it will create an array with the random values between zero and one. So let us check this code. So here as you can see np.tr random dot rand we need to provide the dimension of the array in the tuple. So that is 2a 3 4. So this random function will automatically create this dimensional array having the random values. Let us run the program to check the output. So here you can see that 2 + 3 + 4 array is created using these random values. So using this concept I think you know that numpai's ability to create and manipulate and arrays is a gamecher for scientific computing. You can create arrays from Python list or use functions like zeros, arrange and rand for better efficiency and flexibility. Understanding ND arrays is crucial for solving complex engineering problems such as simulating physical systems or analyzing large data sets. So start experimenting with these methods. You will see how powerful and versatile NumPy can be for your project. We will dive deeper into the foundational aspect of the numpy in our further session. Welcome back everyone. Today we are diving into a foundational aspect of numpy that [clears throat] significantly impacts how efficiently we perform numerical computations. This topic is data types in numpy. So numpy arrays are highly optimized because they allow us to specify the data type of the array elements. Understanding and selecting the right data type is crucial for optimizing memory usage, improving performance and ensuring accurate calculation. In this session, we will explore the different data types available in numpy. how to explicitly define them and how they differ from standard Python data type. Numpy supports a wide range of data types which can be broadly classified as mentioned over here. The first is integer types and it represents the whole numbers and common types are int 8A 16A 32A 64. So these represents the 8 16 32 and 64 bits. Floating types represents the decimal number and the common types for them are float 16, float 32, float 64 and float 128. And here the precision var based on the bits. The complex type is used to represent the numbers with real and imaginary part and it is having the type complex 64 and complex 128. Boolean represents the true or false and it is having the type bull. The next is string type and it is used to store the text data and it is having the type string str or uni code. Object type allows storing the Python objects such as list or dictionaries in the numpy array and it is having the type object. In other data types the unsigned integers represents the non- negative whole numbers and it is having the type u int 8 and the u int 16. It is also used for the date and time data also. Now to understand about all the data types how we can assign this data type to the arrays. For that let us go to the VS code. Here as you can see first we have created an array as we want to check its data type. So array 1 is created using the array function. Next we will print the array one and we want to print its data type. So we will write variable name dot dype. So dt type is the keyword that we need to use. And here the default output for the same will be the int 64. As an example, some of the arrays are provided with the different types of elements. So as we can see the first is integer array. Next is float array. Third is complex array. And within complex array you can see that we will mention np dot array. Within round bracket and within that square bracket we will provide our imaginary number or the complex number. So that number is being 1 + 2 j 2 + 3 j and 3 + 4 j. Here as you can see based on the provided data the data type is defined by the numpy system. We can also create the numpy arrays with the defined data type also. For that we need to make the minor changes in the syntax. So as you can see we are storing the answer in the array one using the np array functionality and it is having the three different elements. Now the default value we know that it is having the data type int 64. So we can change this by providing the comma then d type equal to required data type. In such case this is the int 3. So here based on provided data type the variable is assigned the type. It may be int 8, un 16, plot 32 and the complex 64. As you can see here the provided data types are different and we may change the required data type also based on the requirement using some of the inbuilt function. Here as you can see we have provided one integer array having the array element and the default data type will be integer. Now suppose we want to change its data type to the float. So for that we will store it into the another array that is float array equal to the array which we want to convert that is integer array. Then the function name is type. So dot as type and within bracket we will provide our required data type. In our case suppose we require the float. After converting it, let us print both integer as well as float array to get the difference. So from this program, I hope you got the idea that what are the data types for the array and how we can modify the data type based on the required condition. Let us run the program to check the output. So first you can see that the default data type is integer 64. Then for the second again data type is the int 64. For the next float to 64. Then for the complex array it is complex 128. At the bottom as we see other than provided data type we can also convert the data type of the array and for that required syntax is already provided. Int array is having the data type integer 64 using this a type function. The data type of the integer array is converted to the float. So as we are printing both the data you can see that the first one is int 64 data type second one is the float 64 data type. So as you can see numpy supports a wide range of data types for better control over memory and performance. Next specifying data types explicitly can optimize your code for specific application. Dype attributes help you to inspect or verify the data type of any numpy array. Data types like plot 64 or int 32 are ideal for numerical computation while complex 64 is helpful for handling complex numbers in physics or engineering. So start exploring the flexibility of numpy data types in your projects and you will see the significant impact it can have on performance and accuracy. So looking forward to see you all in our further session. Till then thank you. Hello everyone. Today we are going to discuss numpy array attributes and it is an essential concept when working with numpy. These attributes provide valuable information about the structure and properties of a numpy array. It help us understanding [clears throat] how the array is stored, its dimensions, size, shape, data type and more. By mastering these attributes, you can gain better control over your arrays and ensure efficient data processing in Python. We will start by exploring the general attributes and then dive deeper into these specific ones like endem size, shape, d type and others. So let's start with the numpy array attributes. So numpy array come with various built-in attributes that provide metadata about the array and these attributes include first one n that is it provides the number of dimensions of the array. The next is size and it provides the total number of elements in the array. Now the shape is a tpple representing the dimensions of the array. If we want to check the data type of the elements in the array, we may use the d type. Item size attribute provide the size of each array element in bytes and the data attributes provide the memory address of the array data. So let's take a quick look at these attributes with the example. As you can see in the example, we have imported the numpy and one array is provided and it is the two-dimensional array with the elements 1 2 3 and 4 5 6. So as you can see we have printed different attributes of the array that is first we have printed the array then dimensions of the array using array dot the name of attribute that is the end dim then size of the array next save next data type and same way item size and the data all these attributes are used in this example. So to check the output for the same let us run the program and we will first check output for the first elements only. So you can say the array is printed that is 1 2 3 4 5 6. Number of dimensions is 2. The size means number of elements are six. The shape of the array is 2 + 3. So it is represented in the format of tpple that is 2, 3. Data type of the elements is int 64. The size of the array is 8 bytes and the memory address for the same is also provided using this data attribute. So using these attributes one can get the details about the metadata of any of the array. Next as you can see suppose we want to again check use of nim attribute for the different types of dimensions. Here three arrays are created 1D 2D and 3D and for all these arrays if one want to check if these are exactly the one-dimensional two-dimensional or three-dimensional arrays we may use the ndim attribute. So array_1D end. Same way for all these arrays this same attribute is used. Next suppose we want to check the size again independently the size attribute is used in this example. Further to check the shape one array is created that is the three-dimensional array and the array dots save attribute is used. In the next example as you can see one array is created with the array 1 2 3 and the data type provided is the float 64. And next we will check the data type of the array using this dt type attribute. Next again one array is created and for this data type provided is int 32 and the attribute used is the array dot item size. And the last one again for the created array the data attribute is used to get its location. Let us again run the program to check the output. So here as you can see for this 1D 2D and 3D array the dimensions provided are 1 2 and 3. For the next example, the total number of elements present are six. So array dots size is giving answer to be six. Next array shape is provided for this given example. And here as you can see it is the 2 + 2 + 2 array. So the shape provided is 2a 2a 2 in the format of double. For the next we have already provided the data type to be float 64. So once we are printing the value of d type it will be by default float 64. For the next array, we have provided the three elements and the size of the array is printed using this array dot item size and the size of this array is four bytes. And at last, using this data attribute, one can print the address of this array and it is printed on the screen as you can see. So understanding these numpy attributes gives you complete control over your data and its properties. from analyzing the arrays dimension to inspecting the memory layout. These attributes are indispensable for efficient programming in Python. So now it's time to put these attributes into practice and use them to analyze and manipulate data effectively in your own project. Hello everyone. In today's session, we are going to explore NumPy array indexing and it is one of the core concepts in NumPy that allows you to access, manipulate and modify elements in arrays. Indexing is essential for performing any kind of data manipulation be it for analysis or for computation. We will begin by understanding how to access and modify air elements using indexing. We will also cover negative indexing, 2D and 3D indexing and how to access specific rows or columns of multi-dimensional arrays. By the end of this session, you will have a solid foundation to handle the array data. So indexing is used to access specific elements of array and index for each array starts from zero for the first element 1 for the second and so on. So as you can see suppose here one array is provided having the element 1 3 5 7 9. So the index element of the first element will be zero second element will be 1 and so on it will increase by one. There is also a concept of negative indexing. That means you may refer to the last elements of the array also. But for that the last element position will be referred as the minus1. Then further moving from right to left it will increase negative indexing will be minus2, minus3 and so on. So the first element can be referred as the zeroth element also or minus 5th element also. So this concept is applicable to 1D, 2D, 3D or any multi-dimensional array. So to understand that let us go to the VS code for the program. One-dimensional array is provided having elements 10 20 30 40 and 50. Next we have accessed the element of array and for that we need to write the variable name in which array is stored. So that is array and within square bracket we will provide the index of the element that we want to access. So we know that the starting index element is zeroth element and same way further we will get the further elements. So as you can see in the print statement it is printed first element and array of zero mean array within square bracket zero. So it will represent the first element and that will be 10. Next it is printed array of two. So array of two refers to the third element. So the 10 is zero then first then 2 3 and four. These many index positions are available. So array of two will print the 30. Same way one can use the concept of negative indexing also. And for that as you can see it is mentioned array of minus1 that means it will represent the last element. So it will be 15. Next again second last element that is minus2 and it will be considered as 40. Next you can see one can modify the elements of the array also by referring to that specific element. So here it is mentioned array of 1 equal to 100 and array of three equal to 200. So in given array array of one refers to the second element. So 0 1 2 3 and 4. So in place of 20 we will get the new value being 100. Same way the second and third element will be 40. So the array of three represents to the 200. So 40 will be replaced by 200. Next modified array is printed and four modified array. We can see that the first element will be 10. Next element will be 100 then 30 then again 200 then 50. So this will be the modified array. Next again the array is modified using the negative indexing. So array of minus1 equal to 40 and array of minus3 equal to 20. So again if we consider the modified array the negative indexing start from right to left. So first will be -1 -2 -3 -4 and minus 5. So the new array will be 10a 20 40. So this will be the new modified array based on the assigned negative indexing. Next two-dimensional array is created and for two-dimensional array one need to keep in mind that each blue square bracket represents to the one-dimensional array and it is representing the number of rows available in that array and within each row present of each element represents to the number of columns. So here these first blue bracket refers to the zeroth element of array. Then second is the first element and next is the third element. Now from zeroth element if you want to access one then at zeroth element one-dimensional array is available and within this array we want to access element one. So that means we need to type array of first row element that is 0 comma next column element that is again 0. So 0 comma 0 refers to first square bracket and its first element. So as you can see here it is mentioned that array of 1, 2. First is the zero then one and then two. So the one refers to 4 5 6 within one we need to access the element available at the two index position. So that will be six. So it will print the six. So as we can see this first is referred as the 0 comma 0 then 0a 1 then 0a 2. Next can be referred as 1 comma 0 1 comma 1 and 1 comma 2. And the last refers to 2 comma 0 2a 1 and 2a 2. Next array with the position 0 comma 0. So the first array and its first element that will be 1. Now suppose we want to access the specific row only then we may write array of zero but we will not provide the second element. So it will consider the row available at the zerooth position. So row available at the zero position will be 1 comma 2 3. Suppose 11 1 2 access specific column only. So for that we need to write array of colon symbol and comma 1. Colon symbol at the first refers to the access of all rows available within that array. But within that row second column needs to be printed. So it will print all the elements available in the column available at first index position. So element available at the second columns being 2, 5 and 8. So it will print 2, 5 and 8. Next three-dimensional array is created and within that if you want to access the index position then one must need to keep in mind that this outer blue square bracket refers to the zeroth element. Then second refers to the element available at the first index position. Within that there are two index position. Zero refers to the 1A 2 and 1 refers to the 3A 4. Within these element available at the zeroth position that is 1 comma 2. The element position will be 0 and 1. So as you can see the statement printed is array with index position 0a 1, 0. So the zeroth index position will be this blue square bracket and within that there are two square brackets. So this one is the zeroth index position and second one is the one index position. So within zeroth position we need to access the one index position that is 3a 4 and within these we need to access again element available at the zerooth position. So there are two elements the position of first is zero the position of second is four. So it will print the three. So the output for this case will be three. The next array of 1 comma 0a 1. So first we need to consider the index position available at 1 for the outer bracket. Within this we need to access the zeroth element that is 5a 6 and within this the first element needs to be accessed that is six. So here we will get the output six. Let us run the program to check the output. So as you can see the first element will be 10. Third element will be 30. Last element will be 50. Second last element will be 40. Next, based on the modified values, the modified array is 10, 100, 30, 240. And in the second case, the element will be 10, 100, 20, 240. So here for the second element, we have already updated the value from the first process. So the updated value considered will be the 100. And for the same element available at the third index position the value updated to be 200. So it will be considered as the 200. The remaining process will remain same. So the output will be 10 20 240. Next the element available at the given positions are 6 and 1. Element at the first row are 1 2 3 and element available at the second column that are the 2 5 8. Next, based on the indexing position that we understood, the element at the given position will be three and six. So, by mastering indexing, you can efficiently access, modify, and manipulate array data in both simple and multi-dimensional arrays. Whether it's slicing a 2D array or working with a complex 3D arrays, indexing is a powerful tool for all your data manipulation tasks in NumPy. Keep practicing to gain confidence in these concepts and soon you will be able to work seamlessly with any kind of data structure in Python. Welcome back everyone. Today we are diving into numpy array slicing. It is a vital concept that allow us to access and manipulate specific portion of the array. Whether you are working with one-dimensional or multi-dimensional arrays, slicing gives you the flexibility to extract and modify data [clears throat] efficiently. We will cover the syntax of slicing. We will demonstrate how to slice 1D and 2D arrays and explore the use of start, stop and step parameters and even learn how to reverse the arrays. So let's get started and see how slicing can simplify working with data in Python. So the syntax of numpy array slicing is whichever array we want to slice we will use its variable name. So let us say the variable name is array. Then after within square bracket we may provide the three values start colon stop colon step. Start refers to the starting index and it is inclusive during slicing. Stop refers to the ending index and it is exclusive from the slicing and step refers to the interval between the different indexes that we have selected. And all these values are optional. Based on the selected option we will get the output. To understand the concept of slicing and use of this syntax, let us go to the VS code in the example. Here you can see that we have provided the list of data for the different number of arrays and with the different type of values. So first one array is provided. This is the one-dimensional array. So here we have sliced the data and you can see that we have mentioned array within square bracket 1 col 5. So it is representing the start and stop value. The starting value is the first index element and the ending value is the fifth index element. But keep a note that the five is exclusive. So it will slice the data from first index position to the fourth index position. Now we already know the starting index position will be zero. So we need to start from the one. So we will start from the 20. So it will print 20 30 40. So the index position will be 1 2 3. we will go up to four. So again we will get the value 50. So it will slice the array with the values 20 30 40 and 50. In the next option you can see that here only mentioned array within square bracket colon 4. So before colon it is represented as the start and after colon it is represented as the end. So it will slice the array from beginning to the index three. As four is exclusive we will consider the index position to three. So we will get the output again starting from the beginning that is 10 20 30 and 40. So the index position will be 0 1 2 and 3. In the next statement you can see that the slicing considered to be array of 2 colon empty. So it means it will slice the array from index 2 till the end. So [clears throat] if we start slicing it will start from index position two. So that will be 0 1 2. That means it will start from 30 and it will continue up to end that is 40, 50 and 60. So this will be the sliced array we will get from the given data. Now we may also modify the array elements using slicing. So for that as you can see again one-dimensional array is provided. And here the next statement mentioned is array of 1 colon then after no value is provided that means it will modify elements starting from index one and the value of each element that will be equal to 100. So after this statement if we modify the array so the modified array will be zero index position will remain five and for all the remaining index position it will be value 100. Next, we may also modify the array element using stop parameter also. So here you can see that we have provided the slicing parameter to be array within square bracket colon 3. So the starting index element will be the zero and the ending index element will be the three. So [clears throat] we'll start from 0 1 2 and 3 and the value updated for all these element that will be equal to 50. So if we print the modified array so it will be starting from zeroth index position 50 50 that is up to the index position 0 1 and 2 and for the remaining position the value will remain as it is that is 20 and 25. Next we may also provide the start and stop parameters. So here you can see that array with the index position 1 to 4 that is from index position 1 up to three all the elements will be modified with the values 200 300 and 400. So if we print the modified array we will get the output zero element will be 10 then 200 300 and 400 that will be index position 1 2 and three and the last value will remain same that will be 50. In these we may also include the step parameter also. So in the next example you can see that the slicing data provided are array within square bracket colon col 2 that means starting and ending element will be the zerooth element up to the last element and the step considered to be the two that means at the interval of two the value of each element will be 100. So if we print the modified array we will get the array. The first element will be 100 then two then again 100 then four then again 100 then six then again 100 and last eight. So it will modify every second element. In this slicing we may also use the concept of negative slicing also. So here one-dimensional array is provided and here it is mentioned array within square bracket minus3 colon no value that means up to the end and we know that the negative indexing starts from -1 -2 -3 so we will consider the element from the minus3 and then after from minus3 up to the last element all the elements will be sliced and we will get it printed. So if we print the final answer it will be 40 50 and 60. Using this slicing concept we may also reverse the numpy array. And for that as you can see we may write the syntax array. As we want to reverse each element of this array we will type within square bracket colon that means starting to the ending condition and the minus one that means it will reverse each element of the array. So if we print the modified array, it will print 5 4 3 2 and 1. This concept is also applicable for the two-dimensional array also. Here in the example, next two-dimensional array is provided and it is the 3 + 3 array. So here as you can see the syntax provided is array within square bracket 0 2, 1 3. So before comma element represents the row and after comma element represents the column. So 0 comma 2 refers to that are available at the index position 0 and 1 that will be 1 2 3 and 4 5 6 and within these row we need to consider the column 1 comma 3 that means it will consider element available at the 1 and two index position. So element available at the 1 and two index position will be 2 3 and 5 6. So if we print this modified array we will get element to be 2 3 and 5 6. Next as you can see we have printed array cola 2. That means we will consider all the elements of row that are available at the second indexed column. So here we can see that the first index position will be zero then one then two. So the element available at the second index column that are the three 6 and 9th. So it will print three 6 and 9. At the last statement as you can see again the slicing data provided is array of 1 comma column. That means we will consider all the columns available in the first indexed row. So the row available at the first index position is 4 5 6. So we will get the output 4 5 6. Now let us run the program to compare the output. So we will run the program and here you can see that we are getting the output same way as we have mentioned in the comment also you may compare these output and understand the logic that we have discussed to get this output. So I hope you got the idea how this slicing may be useful to collect certain elements from the array based on requirement from the specific index position. So, this slicing is an incredible powerful tool that allows you to efficiently extract, modify, and manipulate parts of an array. Whether you are working with a simple one-dimensional array or complex multi-dimensional arrays, slicing gives you a granular control over your data. So, practice these concepts and you will be well equipped to handle any slicing challenges in Python. Looking forward to see you all in our further session. Till then, thank you. Welcome everyone. In this session, we will focus on numpy arithmetic array operation. Arithmetic operations are at the core of numerical computing, enabling you to perform element wise calculations, scale arrays or apply mathematical transformations seamlessly. Numpy provides a comprehensive set of arithmetic operations making array based computations efficient and straightforward. So let's begin by exploring the different arithmetic operations available in numpy. Addition operator adds the corresponding elements of the array. Subtraction subtracts the corresponding elements of the arrays. Multiplication multiplies the corresponding elements of the arrays. So same way you can see that these are the different basic arithmetic operators available that we have already understood in the case of simple data types. These same operators are applicable for the array operations also. Let us consider one example to understand the output of these different operators. So go to the VS code here as you can see that two arrays are provided array 1 and array 2 and we will perform different arithmetic operations on this array. So first we are performing the addition on the both array. So result equal to array 1 + array 2. So it will give us the result by adding each individual element available at the same index position. Means we will get 1 + 4 will be 5, 2 + 5 will be 7 and 3 + 6 will be 9. So here keep in mind that it will perform the element wise operation. It may be the addition, subtraction and any operation. Next operation performed is the subtraction. And here you can see that result equal to array 2 minus array 1. So 4 - 1 we will get 3. 5 - 2 3 and 6 - 3 will be also three. Next operation is multiplication. So if we perform the multiplication element wise, we will get the output 4 10 and 18. Next division operation is performed. For that if we execute we will get the output array 2 / by array 1 that will be 4 / 1 it will be 4.0 that is answer will be in the float. Then 5ID by 2 will be 2.5 and 6ide by 3 that will be 3.0. Next is the floor division. So floor division will give us the output of the quotient value with the int data type. So here array 2 floor divided with array 1. So we will get the output 4 / 1 that will be 4. Then 5 / 2 will be 2 and the 6 / 3 will be again 2. So these are the quotient values for the given division operator. Next is the modulus operator and these operator will give us the remainder. So if we perform array two modulo array 1. So four divide by 1 remainder will be zero. 5ID by two remainder will be 1 and the 6ide by 3 again the remainder will be zero. So this will be our output. In the next operation, exponentiation is performed. So here array 1 multiply multiply two. That means it will square each element of array 1 based on the given data. So our output will be 1 4 and 9. And the last operation that is the result equal to minus array 1. That means it will change all the positive values of the given array to be the negative value or the vice versa. So we will get the output -1 -2 - 3. Now to check the output run the program. Now you can compare the our discussed output with the program generated output. And you can see that we are getting the same output as mentioned over here. In this division case we are getting the output 4 then 2.5 and here for the third case if we divide 6ide by 3 then we will get the value to be the 2.0. So here it should be corrected that means 2.0 and for remaining all cases we are getting the same output. So with numpy arithmetic operations you can effortlessly perform computations on arrays in a highly efficient element wise manner. These operations are foundational for numerical computing task and are applicable across various fields. It includes mechanical engineering, data analysis and scientific research. So practice these examples to become proficient with numpai's arithmetic capabilities. Welcome back everyone. Today we are diving into numpy array functions. This plays a crucial role in making numpy such a powerful tool for numerical computing. Numpy offers a wide variety of functions to work with arrays allowing you to perform creation, manipulation, mathematical operations and the statistical analysis efficiently. Understanding this commonly used function will help you to unlock the true potential of numpy in your project. So let's get started. There are different categories available for the array functions. But we will overview some of the most commonly used numpy array function. The first one is the array create functions. So these function help you to create arrays in various shapes, size and initial values. The first one is nparray that converts a python list or tuple into a numpy array. Next np.zeros. It will create an array filled with zeros. The next is np once. So it will create an array filled with ones. And the last is np. And it will create an uninitialized array. To use this function, let us go to VS code. Here you can see that we have created four arrays. Array 1 np. Within which we have provided the list which we want to convert it into the array. Second is array 2, np.zeros. And within this the dimension of array is provided in the format of tuple. So 2a 3 refers to the 2 + 3 array and it will be filled with zeros. Array 3 equal to np do.1 3a 2. It means it will create a 3 +2 array with all the values being 1. And array 4 equal to np 22 refers to the 2 +2 array and it will create an uninitialized array. We have printed all these array. So let us run the program to check the output. So here you can see that the first array is created 1 2 3. The second 2 + 3 array is created with all the default values being 0.0 that is in the float data type. Next once array is created and it is having the dimension 3 +2 and the last empty array is created and it is the uninitialized array. Next we will understand about the array mathematical functions. These functions perform element wise mathematical operations. Some of the widely used mathematical functions are noted over here. The functions such as add, mean, max, square root and power are useful for mechanical engineering perspective also. We will understand the use of these functions using one example. So let us go to VS code. Here two arrays are provided array 1 array 2. Now first we are trying to find the minimum element from array 1. So we will use np dot mean and within bracket we have provided the required array that is array 1. So this function will give us the minimum element present from this array one and that will be one. Next function is max and within its argument array one is provided. So it will find the maximum element from given array and that will be nine. Next is add function and within its bracket two arrays are passed that is array 1, array 2. So it will add each element of this array and it will be stored into the variable result add. So the output of these result underscore add will be element wise addition that is 2 6 and 12. The next function is square root. So it will find the square root of each element of the array 1 and we will get the output 1 2 and 3. Next function is the power and here you can see that the first we have provided the array and then after we have provided the power for the each element. So this will find the power of each element present in the array two. So it will find the square of each element. So output will be 1 4 and 9. Now the output for each variable is printed using this statement. So let us run the program to check the output. So here you can see that the minimum element is 1, maximum element is 9, addition is 2, 6 and 12 and in square root as you can see whenever we are finding the square root the output will be default float data type. So we will get the answer to be 1.0 2.0 and 3.0. Next the power value will be again 1 4 and 9. So I hope you got the idea how to make use of these mathematical functions. Next we will discuss about some of the array statistical functions. So these functions perform statistical analysis on array elements. So some of the most widely used statistical functions are mean, median, standard deviation and variance. To understand the use of this function again let us consider one example. So go to VS code. Here we have provided one array having the element 125. Now we are finding all necessary elements that is median. So we will type np dot median and within its argument we will pass the array for which we want to find its value. Same way we may use the functions mean, standard deviation and variance and the answer for all these variables are printed using this print function. So let us run the program to check the output. So here you can see that the value of median is 3.0 that is the middle element present in the given array when it is shorted in the ascending order. Next is the value of mean that is the average. So it is the sum of total numbers divide by count of total numbers. The next is standard deviation and the last one is variance. So if needed in any mathematical computation we may find the standard deviation and the variance value also directly by using this inbuilt function. So in this session we explore the most commonly used numpy functions and categorized by their purpose. So whether you are creating arrays, performing mathematical or statistical calculations, NumPy has the tools that you need. These functions are the building blocks for solving complex numerical problems efficiently. So practice these examples to master their use and unlock the power of numpy for your projects. Hello everyone and welcome back. Today we will explore a unique feature of numpy that goes beyond numerical operations that is the string functions. While NumPy is primarily known for handling arrays and numerical computations, it also provides powerful tools for string manipulation. These functions are useful for processing text data in arrays making it easy to perform task like concatenation, case conversion, repeatation and more all at array level. Let's take closer look at some common string functions provided by the numpy and their applications. So here is the list of commonly used string functions in numpy and we will understand the use of all these function using one example. For that go to VS code. Here one standard program is provided for the understanding purpose. Two arrays are provided array one and array two and they are having the string data type elements. Now first is the add function and it concatenates two strings element wise. So here you can see that we have stored it into the variable concatenated equal to to use this functionality of string function. We may type np dot care is compulsory then dot the function name add and within its argument we will pass the number of arrays that we want to concatenate. So here we have passed array 1, array 2. Then we have printed the concatenated array. So here we will get the output. First hello world that will be concatenated then numpy functions and in third we will get the output python python. So one array is created with the name concatenated and it is having the concatenated strings. Second function is the multiply function and it repeats the string for a specified number of times. So we have stored it into the variable repeated equal to np.care dot multiply within its argument. First we will pass the array comma separated. We will pass the number which represents the number of times we want to repeat the string. So here the number is two that means when a new array will be created it will be stored into the repeated variable and it is having the elements hello numpy numpy and python python as here two is mentioned which indicates the repetation of each element two times. Third is capitalize function and it capitalize the first letter of each string in the given array. Now to use this again same methodology we will adapt np do. care dot capitalize within its argument we will pass the array. So it will capitalize first letter of each element of the given array. So here array one is passed. So for that it is having first element in lower case. So it will keep h capital n capital and p capital. The fourth one is the lower function and it converts all uppercase characters in a string to the lower case. To use this we will only type np do.care dot lower and within its argument we will pass the array two. So here array 2 is passed. So it will consider all the elements of array 2 and any uppercase character present in the given string will be converted to the lower case. The fifth one is the upper function and it converts all lowerase characters in a string to the upper case. So we may use the function in the same way as the lower. We will type np.care dot upper and within its argument here we have passed array one. So now this function will convert each element string and its character to the uppercase. Sixth function is the join and it joins the elements of a sequence into a single string by using the specified character. So here we will type np.care dot join within its argument. First we will pass the character with which we want to join each character of the string. Then comma separated we will provide the array name. And here we have provided the array one. So in this case it will create a new array. And in this array each element of the array and within that each character of the string gets connected by this dash symbol. So as an output we will get hash e- l- o as of first. Then in second we will get n - u - m d-p. That means it will combine each character of the string by this provided character. Now the last function that is the equal function and it checks the equality of the strings from the given arrays. So here we have mentioned np.care doe equal within bracket we want to compare the elements of array 1, array 2. So we have passed array 1, array 2. So it will compare each element of the given arrays at the same index position and if these two matches then it will return the answer true and if does not matches then it will return the answer false. So in our case first two elements are not matching so we will get the answer false. For the second also we will get the answer false but in the third case both elements are matching so we will get the answer true. Now to check the output let us run the program. So here you can see that first strings are concatenated of the array 1 and array 2. So we are getting the output hello world numpy functions and python python. As a second case in the multiply function the repeatation provided is for two times. So we are getting the output hello numpy numpy and python python. In the third case the first letter gets capitalized due to this function. Due to use of lower function the each string elements are converted to the lower case and due to use of the uppercase function each element of the string is converted to the upper case. In the next join function as you can see each character of the strings are connected by the provided dash and in the last case in the equality check using the equal function each we have compared the elements and we are getting the output false and true. So I hope you got the idea how to make use of the string functions to get the idea about the string to perform the manipulations operations on the string elements available in the array. So these numpy string functions are extremely versatile and allow you to manipulate text data directly within arrays. Whether it's concatenating strings, changing case or repeating patterns, these functions help streamline text processing task in Python. So you can imagine this being particularly useful in scenarios like formatting or cleaning data in machine learning pipelines, processing text in CSV or database records for preparing labels or annotations for visualization. So that's all for today's discussion on numpy string functions. Try experimenting with these functions in your own project to see how they simplify text manipulation task. Hello everyone, welcome back. In this session, we will understand use of some of the important trigonometric function. Numpai provides a comprehensive set of trigonometric functions that help compute the trigonometric ratios of angles such as s, cosine, tangent and their inverse. These functions are especially useful in engineering and scientific computations where angles and rotations are involved. Commonly used trigonometric functions in numpy are sin cosine tan inverse s inverse cosine inverse tangent and conversion to degrees and radians. Let us consider one example to use this function. For that go to vs code. Here for your reference some data is provided and the use of these functions are also provided. But for this import of numpy module is important. So first we have imported the module import numpy as np. So we may use the numpy as alias of the np. Here angle is defined as the 45. Now we can convert this angle to radians also. For that we may type angle radian equal to np dot radians and within which we will pass our degree angle. So it will convert our degree angle into the radians value. Next we may calculate the s cosine and tangent value also. For that we may use np dot sign and within which we will provide the angle. And here the angle provided is in radian. Same way we may use the function np do. cos and np.10 within its argument we may need to pass the value of angle. Now the stored value s cosine and tangent are printed using this print function. We may also use the inverse trigonometric functions to find its value. So here you can see that we have stored its values into some of the variables. So suppose we want to find the sign inverse for that np sign and within its argument we will pass the sign value and these values we have already calculated using these above functions. Same way we may use the arc co and arc 10 function also which will provide the inverse trigonometric values. All the calculated values stored in this variable and these values are printed using this print functions. Next, if we are having the angles in radians, then we may convert these angles into the degrees also and for that we may use the function np do. And within its argument, we will pass the radian angle and same way vice versa is also possible. So these degrees and radians functions are useful to convert the angle into the radians over degrees. Now use of these functions are also shown over here and some of the data is printed using this print function. Now there is also possibility that we may convert the range of angles from degree to radian using these functions also. So as you can see in this example we are having the angles in degree in the format of array that are np dot array we are having the angles 0 30 45 60 and 90. We can convert these angle into the radians using these radians function. So np.t radians and these array of degree angle is provided as an argument and same way using this array concept we can pass these angles radian variable that is having the array of radians into the s cosine and tangent also to calculate element wise values from this array. So these functions are useful for calculating the single values as well as the element wise values from the arrays also. Let us run the program to check the output. So here you can see that the angle is 45° and using these radian functions we have converted into the radian. Same way the value of sin cosine and tangent 45° is obtained using the sin cos 10 value. But here keep a note that within this function we will pass the radian angle. Same way we may find the inverse trigonometric data also. So based on the provided radian value we may find the values of angles also. And this may be possible by using this ark sign, arc co and arc tangent function. Next we have converted the degree to radian and radian to degree using this degree and radian function. And you can see the output. And same way at the bottom we have passed the array of degree into the radian. So we have converted the value into the radians. And same way we may find the values of s, cosine and tangent also from that each element of array. So I hope that you got the idea how we may use these trigonometric functions to calculate the data based on the provided angles. It may be a radians or it may be in the degrees. You may use these trigonometric functions while performing some of the mathematical operations or the matrix operation in which the rotations or the angular movements are involved. Keep practicing these functions so you may get better idea how to utilize and where to utilize these functions. Looking forward to see you all in our next session. Till then thank you. Hello everyone. Today we are diving into numpy matrix operation and it is an essential part of numerical computations for handling multi-dimensional data. We will explore a range of matrix operations including multiplication, transpose, inverse, determinant and reaping. These operations are crucial in engineering, data science and scientific research. So now let's understand these operations step by step with the examples. First is the dot function and it is useful for performing the matrix multiplication. This calculate the dot products between the two matrix. The second function is the transpose function and it will convert the rows into columns and vice versa. So this function flips a matrix over its diagonal converting rows into columns and columns into rows. The next is inverse function and it computes the inverse of a square matrix and this inverse function is from the line. The fourth function is the determinant. So it calculates the determinant of a square matrix and again it is available from the clean. The next function is the flatten and this converts the n dimensional matrix to the one-dimensional array. And the last function is the reshape which changes the shape of array without altering its data. So we may change the type of array by using this resave function. So let us understand all these functions using one program. So go to v score. Here you can see that first we have imported the numpy and as we want to use the function inverse and determinant which is available in the line and this line is available within numpy. So we have mentioned from numpy. Lineal import inverse comma determinant that is inv. We have provided the 2x2 matrix. It is having the elements 7 5 and 2 3. First we have printed the original matrix. Now suppose we want to find the sum of diagonal elements of this matrix. So for that the function available is trace. So we will type np trace within which we will provide our matrix. [clears throat] So it will find the sum of diagonal elements of the matrix. We can find the transpose of a matrix. For that we may type np.transpose and within its argument we will pass our matrix. To find the inverse of a matrix we will use the function inv. and within its argument we will pass the matrix. We may also calculate the determinant using the same function that is det and within its argument we will pass our required matrix. Now any n dimensional matrix can be converted to the one-dimensional matrix using this flatten function and to use this we first need to type the array name that is matrix and dot we will use the function that is flatten and we will pass no arguments. Now this flattened one-dimensional array can be converted to the any required shape by using the resave function. So you can see that we have mentioned flatten dot resave and we want to convert these one-dimensional array to 1x4 matrix. So we have mentioned value to be 1, four. It represents one row and four columns. We may find the multiplication of these two matrices also. And for that the function available is dot function. So here you can see that the first matrix is having the values 7 5 2 3. Second matrix is defined over here having the values 1 2 3 4. So suppose we want to find the dotproduct between these two matrix we will type np dot dot and within its argument we will pass our matrix that is matrix matrix_b. So it will find the multiplication between these two matrices. Let us run the program to check the output. So here our original matrix is 75 23. Its diagonal elements are 7 and 3. So the trace of matrix obtained that is the 10. Next we have found the transpose of matrix. And here you can see that the elements of rows became the elements of column. So 75 and 2 3. Next we have also obtained the inverse of matrix. We very well know that finding the inverse of matrix is a timeconuming process. But using this function you may directly find the inverse of matrix. Next determinant of matrix is also obtained using the d function. We are having this two-dimensional matrix 7523 and using flattened function it is converted to the one-dimensional array that is 75 23. Next these one-dimensional array is converted to the two-dimensional array having the one row and four columns. So you can see that here two square brackets are provided and it is having the one row having elements 7 52 3. And finally we have also printed the dotproduct of these two matrices. And again we know that this process is timeconuming to find the multiplication of two matrix. But using this dot function we may easily find the multiplication between the matrices. So I hope you got the idea how we may perform these matrix operations by using some of the inbuilt functions available within numpy library. These operations enable you to perform essential matrix computation effortlessly with this numpy. So practice combining these operations in program to gain the proficiency. Hello everyone, welcome to today's session. In this session, we will be applying Python's library to solve engineering problems numerically. In mechanical systems, analytical solutions are often impractical for complex geometries or dynamic conditions. This is where numerical methods tap in and numpy serves as our toolkit. From solving systems of linear equations in a structural analysis to performing numerical integration for thermodynamic cycles, Numpai's array manipulation and mathematical functions make it both powerful and efficient. By the end of this session, you will understand how to translate engineering problems into a code and achieve precise reliable solution. So let us start with the first example. The statement given is a mechanical component experiences a stress in the three perpendicular directions and the stress tensor is provided. We need to calculate the trace of the stress tensor. Second, we need to find the determinant and inverse of the stress matrix and third we need to find the transpose of the matrix. Now to solve this problem, first we need to define the stress tensor. To define this we need to create a 3 +3 array and for that we may use the np dot array function. So here we have defined the stress tensor using the np dot array function. Now to perform the first task we need to define the variable in which we will find the value of trace and to find the value of trace there is inbuilt function available in the numpy that is the trace function. So just we need to store that answer into one variable. So trace value equal to np dot trace and within its argument we will pass our array to find the determinant and inverse we need to specifically use the lin elk part of the numpy. So here determinant is stored as np. Linel dot date that is the de which represents the determinant within its argument we have passed the required array. To find the inverse of the matrix again np.el green dot function available is inverse that is I and V and within its argument we will pass again our required matrix. So answer of both get stored into the determinant and the inverse matrix variable. Now to find the transpose again within numpy library transpose function is available. We need to store its answer into the variable. So transpose matrix equal to np.transpose and within its argument we have provided our required array. So using all these inbuilt functions we can easily perform the required mathematical computation based on our given problem. Finally we are displaying all the results that we have calculated from the above steps. So we are printing stress tensor stress determinant inverse of the stress tensor and the transpose of the stress tensor. Let us run the program to check the output. So here you can see that first stress tensor is provided. Now second trace is calculated that is nothing but the summation of the diagonal elements that will be 470. Next determinant of the stress tensor that is again calculated using the inbuilt function. Next we have obtained the inverse of the stress tensor and finally we have also obtained the transpose of the stress tensor. So based on need you may again perform further calculations also and numpy will be the tool that may be helping you to solve these type of problems. Let us go to second example. So here the statement is a mechanical shaft is subjected to dynamic loads causing angular displacements over time. The angular displacement changes from 0 to 90° and we need to calculate the s cosine and tangent values. Then we need to convert angle from radian to degree. At last we need to find the inverse of the trigonometric functions for the selected values. So to perform this first we need to consider the angle in degree. So we are storing it theta degree that is equal to 45. Next to convert this angle into the radian we need to use the inbuilt function that is dot radian. So we will type angle in radian equal to np dot radians and within its argument this theta degree is passed. Now to find the s cosine and tangent values again these functionalities are available within numpy. So we will use the function np dots sine np. dot cos and np.10 and within its argument we will pass the radian angle. So the value of sine, cosine and tangents are stored into these three variables and the inbuilt functions are used. Now to perform the second step, we may use the inbuilt function that is degree or radian to convert the angle vice versa. We are converting from radian back to degree that is np degrees and within its argument we will pass our radian value. After getting the degree value again we may find the inverse trigonometric values using the inverse trigonometric functions that are the ark sign arc cos and ark 10. So we are storing its answer again into three variables that is ark sine cos and 10 values and within these functions we are passing our angle value in degrees. So in the first step we have provided the angle in degrees. Then we have converted this angle into the radian. Using these radian angles we have calculated the trigonometric values. Again this radian angle is converted back to degree and using this degree angle we have calculated the inverse trigonometric values. Finally we are displaying all the results that are for the angle conversion and the trigonometric and inverse trigonometric values. So let us run the program to check the output. So here you can see that the angle is 45° and its corresponding radian value is provided. Then sin, cos and 10 angle values are provided. Then again using the degree values again inverse trigonometric functions are calculated. So with the use of trigonometric functions you may easily perform these type of calculations where you do not need to write the code that how to calculate s cosine and tan but you may use the inbuilt functionality. Let us again consider the third example. So here the scenario given is a mechanical lab stores a list of material names in uppercase steel, aluminium, titanium. There are certain steps that we need to perform. First we need to convert all material names to lower case. Then we need to capitalize the first letter of each material name. Then we need to concatenate material names for the documentation purpose. And fourth we need to repeat material name multiple times for the labeling purpose. So let us first define the array of the materials that is materials equal to np dot array and the three materials are provided. Now to convert the name of these materials into the lower case in numpy inbuilt function is available that is the dot lower. So lowerase materials that is equal to np dot care dot lower and within its argument we will pass our array. Now to capitalize first letter of each material name there is inbuilt function is available that is capitalize. So to use that we will again type np do.care dot capitalize and within its argument we will pass our lowerase materials array to show the concatenation operation again we may use the inbuilt function concat and for that the function name available is the add. So we will type np.care care dot add and within its argument we have passed the two materials from that array that is material at zeroth index position and material at first index position at last for the repeatation of the material name there is inbuilt function available named multiply so we will use npcare domultiply within its argument first we have passed our required array comma 3 represents that the each name gets repeated three times in the given array after performing all The required operation we are displaying the results based on the performed steps. So we are printing the list of original materials then lowerase materials then capitalized materials then concatenated names and finally the repeated labels. To check the output run the program. So here original materials are listed over here. Then we have converted it to lowerase materials. Then the first letter of each material is capitalized. We have concatenated two elements zerooth index and the first index. So we are getting the output steel combined with the aluminum and this operation is performed on the original array. So we are getting this first capitalized letters concatenated at this point and at last we are getting the repeated labels. As you can see steel is multiplied three times, aluminum is multiplied three times and same way the remaining materials are multiplied by three times. So if there is any need of string manipulation during the array operation also then at this point some of these string functions are also useful to perform these task. So I hope with these examples you got the idea how one may use the different array functions available in the numpy to perform it may be a mathematical operations or it may be a text type operations. So keep practicing this tool try to implement these functionalities to have better clarity about benefit of using numpy in our regular task. So looking forward to see you all in our further session. Till then thank you. Hello everyone and welcome back. Today we are going to talk about how Jet GPT can be an incredibly powerful tool for troubleshooting numpy related issues. Whether you are a beginner or an experienced programmer, Jet GPT can assist you in solving errors, optimizing code, and deepening your understanding of numpy operation. One of the most common challenges when working with the numpy is facing unexpected errors like safe mismatch, index, out of bounds or unsupported operant types. So instead of spending hours searching for solution, you can simply describe the error to chat GPT and the Jet GPT can quickly identify that type of error and it will guide you to use the correct syntax with proper informations. You may also learn the important numpy operations using JG GPT. For that you need to provide your required prompts. Here are some of the important prompts that you may provide based on your requirement. Now suppose you are a beginner to understand the numpy. So you may first ask the question that how do one can create a numpy array with specific values. So suppose we are providing the data how do one can create numpy array with specific values. So here checkp will analyze your question and it will provide the data based on your requirement. So here you can see that we may use the inbuilt arrow function, pull function, zeros, ones, arrange function. So all these functions we have already understood and other than this there are list of different functions are available. You can also master that functions using the Jet GPT. So here there are list of different operations are provided. Suppose you want to understand some of the important mathematical functions available in the numpy. Then also you may provide the prompt such as explain all important functions available in numpy for mathematical operations with syntax and hit enter. Here you will find the list of different mathematical operations that you may perform and that are available within this numpy library. Some of the functions we have already understood but other than that there are also list of different functions are available that you may master using this JGPT. So here you can see that there are so many aggregation functions are also available that are sum product cumulative sum cumulative product then statistical functions and so on. You will find the list of different operations that you may perform using these numpy library. So I hope you got the idea how you may master the numpy using these chat GPT as your important partner. There are list of functions available that are goes on that you may use based on the requirement. Now after understanding all the important functions suppose you want to have the practical applications so also you can ask the chat GPT about the practical applications that is it may generate some of the programs also. Suppose we want to generate a numpy program to solve a system of linear equations. So we may provide the prompt generate numpy program to solve a system of linear equations. So here you can see that JPT has provided one code providing the array then some of its important data. So using this concept you may get the practical applications also and how to solve that type of problems. To the left hand side you will find the explanation for that code also. Now here you will find the option also suppose you want to have the answer in chat instead. So you may select this and here the entire problem and its answers are provided in these chat box only. So here you will see that two linear equations are provided and to solve these linear equations you may use these inbuilt functionalities available. So with this I can say that CGP isn't just a troubleshooting tool. It's your 24x7 coding assistant, debugger, and tutor for NumPy. It helps you fix errors faster, learn concepts better, and write cleaner and more efficient code. So the next time you face a numpy challenge, don't hesitate. You can just ask this to JPT. Hello everyone. Today we are diving into one of the most powerful and widely used libraries in Python for data analysis that is pandas. If you have ever worked with data, whether it's organizing spreadsheets, analyzing trends, or preparing data for machine learning, you will find pandas incredibly useful. But what exactly is pandas? So, pandas is a open-source Python library designed for data manipulation and analysis. It provides two main data structures that is series and data frame. And that we will understand in detail in our further sessions. Pandas has become an essential tool for data scientist, analyst and engineers worldwide. Pandas is mainly used for data cleaning. So it is used for fixing missing values, removing duplicates and handling inconsistencies. Second, it is useful for data manipulation such as sorting, filtering, grouping and merging data sets effortlessly. It is also used for data analysis to perform statistical calculations and descriptive analytics. It can work with metplot li and cun for the data visualization to create the charts and graphs. Pandas can handle large data sets and it can help you to work with millions of rows efficiently. And the major important advantage is you can read or write data from CSV, Excel, JSON, SQL and other formats also. In short, if you are working with data, pandas makes everything simpler and faster. Now you might wondering why use pandas when python already has list and dictionaries for storing data. So pandas is designed for efficiency and ease of use. Pandas is built on numpy making data handling quicker than traditional list. It can provide powerful functions for filtering, grouping and transforming data with just a few lines of code. It is compatible with numpy, metlot lip, seabon and scikit learn type of library also. And in real world application, it is used in finance, healthcare, marketing, machine learning and many more sectors. So instead of manually processing data in Excel or writing long Python loops, pandas allows us to work more efficiently. So before we can start using pandas, we need to install it. And the installation process is simple. You need to open your command prompt or terminal and just type pip install pandas and hit enter. But make sure while executing this line you are having working internet to install this pandas library. And once installed pandas is ready to use. Now that you have pandas installed you need to import it into your code. And the standard convention to import the pandas is you need to type as a first line import pandas as pd. And here pd is a sword alias for pandas which help us write cleaner code. So pandas is must-h have library for data analysis in python. We explored that pandas is its importance installation and how to import it. In the next sessions we will dive deeper into data manipulation and real world applications. Thank you for joining this session and looking forward to see you all in the next lecture. Hello everyone. In our previous session we introduced pandas and learned how to install and import it. Today we are going to focus on one of the fundamental data structure in pandas that is series. Pandas series is a one-dimensional labeled array capable of holding any data type. It may be integers, floats, string, etc. But keep in mind that it is useful for one-dimensional array only. It is similar to a column in Excel spreadsheet or a list in Python but with additional functionalities. Each element in series has an index which act like a row label. Let's create a simple pandas series to understand how it works. For that let us go to VS code. Here we have imported pandas and for that the line mentioned is import pandas as pd. Here we created a series of numbers 10 to 50 and for that we have stored the value into the variable data and the function used is pd dot series. Within its round bracket the data array is provided. So within square bracket data provided is 10 20 30 40 and 50. And then after the data is printed. So within print argument data is passed. Now to check the output let us run the program. So here you can see that the series of numbers are created from 10 to 50 and the numbers on the left that are 0 to 4 are default index labels just like the row numbers in a table. And at the bottom the data type is provided and for this the data type is int 64. So using this series function one can create the simple panda series having the default index numbers. As you can see by default pandas assign a numeric indexes starting from zero. However we can customize these index levels. To understand that let us again go to the next program. Here you can see that we have provided the data that is equal to PD dot series within round bracket elements are provided within list that is 10 20 30. Now comma we will write the labels for the index. So comma index equal to within square bracket we will provide the label for the index which we require. So here we have mentioned a comma b comma c. Then after the data is printed. So now for this the output will be the element will be 10 20 30 and the index number for the same will be a b and c. After creating series we can access the values also by using labels or by using the index numbers. So suppose we do not want to print all data but we want to print a specific element at that point we will type print within its argument data that is being our variable name and within square bracket we may provide label or the index number. Currently within double quote the value B is provided that is the label. So this B label will be assigned to 20. So our output will be 20. Other than this we may also provide the index number. So next you can see that print data within its square bracket provided one. So here one refers to the index number. So again index number start from 0 1 2. So one refers to the element 20. To check the output let us run the program. So here you can see that now the element will be 10 20 30 but the index labels are a b and c. The data type being int 64 only. For the second we are getting the output 20 and same way for the last one that is for the index label we are also getting the output 20. So whether you use default index or custom labels pandas makes it easier to retrieve the data. Till this example we understood that using list we can create the pandas series. But there is also another option available to create a series and that is from the python dictionary and this is very useful for handling the structured data. So to understand that let us go to the third example. So here you can see that first we have created one dictionary that is within its curly bracket we provided key value pair key being the apple and value being the 50 comma banana col 30, orange col 40. Now this dictionary can be converted to the series and for that we can use pd dot series and within its argument we will directly pass our dictionary. So here index will be the apple banana and orange and the value being the 50 30 and 40. Let us run the program to check the output. So here you can see that apple 50 banana 30 orange 40 and the data type being the int 64. So here keep in mind that the keys of the dictionary become the index labels and the values of the dictionary form the series data. This method is useful when working with real world data sets where data is naturally stored as key value pairs. Now to understand use of all these concept, let us consider one example in the context of mechanical engineering. So imagine we are analyzing the properties of different metals used in mechanical design and for that we want to store the metal densities in a pandas series. So let us first store the material name and its value into the dictionary data and then we will convert it into the pandas series. So here you can see that metal density equal to aluminium colon value is provided. Same way for the different materials values are provided. Next we are converting it into the series for that PD dot series and within its argument this dictionary data is passed and then we are printing the final material and density data. Now there is a possibility that we want to access the value of a specific material. So for that we can access this using variable name that is density series and within it square bracket we will provide the label name and label name. Suppose we want to have the properties of density of titanium. So as a label we have provided the titanium. There is also possibility that if you want to filter the metals with the density above 5 g per cm cube and for that very simple approach is available and we are storing that answer into the variable filtered equal to density series and within it square bracket we will provide our filter logic. So density series greater than five. So it will filter all the data having the density greater than five. And finally we have printed that filtered data using the print statement. Let us run the program to check the output. So here you can see that all the materials are listed with its data type. The density of the titanium is accessed and its value is 4.5. And now the data is filtered based on the given entry that is from these elements whichever material is having density greater than five that all are filtered and printed over here. So you can see that engineers can quickly compare densities when selecting materials for lightweight or high strength applications. The data can be filtered, sorted or processed for further analysis in material science and manufacturing. And about these we will learn in detail in our further sessions. So to summarize today we learned about pandas series, how to create them from list and dictionaries and how they can be applied in mechanical engineering. In our next session, we will explore pandas data frames which allow us to work with multi-dimensional data. Thank you for joining today. Keep practicing and see you in the next session. Hello everyone. In our last session, we learned about pandas series. Today we will focus on pandas data frame which is the most commonly used data structure in pandas for handling tabular data. A data frame is a two-dimensional labeled data structure similar to a table in Excel or SQL database. It consists of rows and columns where the each column is essentially a pandas series. Data frames allow us to store, manipulate and analyze the structured data efficiently. The key features of the pandas data frame include it can hold different data types such as integer, floats, strings, etc. It can support custom indexing for rows and columns. It allows easy data filtering, shorting, and transformation. and it works well with large data sets and integrates with databases CSV, Excel and more. Now let's explore different ways to create pandas data frame. To understand that let us go to the VS code. So the first way is to create a data frame from a Python dictionary and it is best for small data sets where data is naturally structured as a key value pair. So here you can see that the data is having the key name, age and department and it is having the values in the array format. So the key is having the string data type whereas the value is of list type. So the names stored are Alice, Bob and Charlie. Their age are 25, 30 and 35 and their departments are mechanical, electrical and civil. So all these data stored as a dictionary format. Now to create a data frame we will type PD dot dataf frame and within its argument we will pass the dictionary. We may print the data frame using the print function and we will pass our variable here. Keep in mind that the keys of the dictionary become column names and the values become rows of the data frame. As we understood in the concept of series the default labels are provided that are starting from the 0 1 and onwards. Same way in the data frame also the default index labels are provided and that will start from 0 1 2 onwards. We can also add the custom label and for that we may type df dot index equal to now we can define the index label that we want to provide. So suppose we want to provide the index label c001 c00 02 and c003. So again these values are provided in the format of list. After execution of these line the index labels will change and the custom labeling will be applied. To check that let us run the program. So here you can see that column names are name age department and these are nothing but the keys of the dictionary. The default indexing labels are provided that is 0 1 and two and remaining all the entries are provided. Now after execution of this custom labeling line you can see that the the labels have changed from 012 to C001 C002 and further. So I hope you get the idea that using data frame function we can create the multi-dimensional data and we may represent it in the format of row and column as the data is available in the tabular format. You are also having the option to provide the custom labeling and for that you need to use the index concept. Now here you can see that we have provided the some default data available within dictionary and that dictionary is converted to the data frame. But there may be a chances that the structure of data is no one but we want to add the data later and for that there is also option available to create the empty data frame. So to understand that let us consider another program. So here you can see that we are writing df equal to pd dot dataf frame and within its argument we are only providing the names of columns. So for that columns equal to name, age and department and then we are printing the data frame. So it will only define the column names but the data will remain empty. Now then after we can add the data to this empty data frame using this lock functionality and about this we will understand in detail in our further session. But to just get the idea here we will mention DF do.lo within its argument we will indicate the index position that is zero equal to we will define the data name age and department. So that will be lis 25 and mechanical. Same way for the index position one further data is provided and then finally we are printing the data. To check that let us run the program. So here first you can see that the columns are defined but the index values are empty. Now after adding the data at the index position zero and one name, age and department values are added. So you may use this concept also whenever you are having the structure of the data but you want to add the data later based on the requirements. Now let us see how a data frame can be useful in mechanical engineering context and for that consider this example. So suppose we are analyzing the mechanical properties of different materials used in the engineering design and for that all the properties of different materials are listed in the format of dictionary. So the materials density yanks modulus and the tensile strength data are mentioned in this dictionary format. This dictionary data will be converted to data frame using PD dot data frame within its argument. This dictionary is passed. Then finally data is printed. Now suppose from this data we want to have the materials having the tensile strength greater than 500. So here you can see that we are having the list in which key and value combination is available and in the value again we are having the list. So from that list we want to extract the data. So we will mention suppose we have stored it into the strong materials equal to DF refers to the outer data. From that outer data again we want to represent this inner list. So again we will mention DF within square bracket. Again df within square bracket we will provide the label that is tensile strength megapascal and from this we want to have the element having the tensile strength greater than 500. So we have mentioned greater than 500. So it will collect greater than 500 values from this tensile strength and from these values again it will consider the key data from these entire materials section. So it will store only the data of materials which are having the tensile strength values greater than 500. To check the output let us run the program. So the data for four materials are added and the columns are material density youngs modulus and tensile strength. Then after using this filtration we are getting the list of materials which are having the values of tensile strength greater than 500 that are steel and titanium. So engineer can compare material properties before selecting them for structural application. This filtering materials based on criteria is also helpful to filter the data. So today we explored the pandas data frame, its structure, how to create it and its practical applications in mechanical engineering. In our next session, we will dive into data frame operations. Here some key points that you need to keep in mind are the pandas data frame is a 2D labelled data structure for handling structured data. It can be created using dictionaries, list, files or empty structures. Data frames are useful in engineering data science and real world applications and mechanical engineers can use them to store and analyze material properties also. So thank you for joining today's session. Keep practicing and see you soon in the next session. Hello everyone. In our previous sessions, we learned about pandas series and data frames. Today, we will focus on an essential part of pandas that is indexing. The index in pandas is used to uniquely identify rows in data frame or series that we have already understood in our previous session. It helps in faster data retrieval, filtering and alignment when performing operation. By default, pandas assign an integer based index. But we can also set custom index. This pandas index help in fast data lookup. Supports custom and hierarchical indexing and it can be reset, modified or set from existing columns. So let's explore different ways to create and modify index in pandas. And for that let us go to PS4. Here data is created using the dictionary. The columns being name, age, department and its datas are provided. This data is converted to data frame using functionality PD dot dataf frame and within its argument variable data is passed. Then data of data frame is printed using this print function. Here by default pandas assign an integer index starting from zero. To check that let us run the program. So here the original data frame datas are printed and the index is starting from zero. So these default index are autogenerated and this index can be replaced with the custom values. Now to provide the custom index we need to use the inbuilt functionality that is set index and here we have mentioned df dot set index the index value that we want to set that is the name of the data. So within double quote we have provided the label that is name comma in place equal to true. So with the execution of these line the name column is now the index and the in place equal to true modifies the data frame directly. Then further the data frame data is printed. So again run the program. So after setting the custom index you can see that the index names are Ellis, Bob and Charlie. Now suppose we want to reset this custom index then it is also possible and for that we need to use the inbuilt functionality reset index. So here df dot reset index within its argument in place equal to true is passed. So it will restore the index with the original format. Then again this data frame is printed. So to check the output run the program. Now here you can see that after resetting the index further we are getting the numbers 0 1 and 2. But in almost cases it is suggested to provide the custom index as if a column contains a unique values setting it as an index can help in a faster lookups. For example for the time series type data setting date and time as an index is beneficial. Now other than this there is also one option is available to create a range index and it is useful when one want sequential numbering of rows. Now to provide the range index we need to again use the inbuilt functionality that is pd dot data frame within its argument we will pass our dictionary type data. Then we will define the index and index will be comma index equal to pd dot range index. within its argument we will pass three data start stop and step. So suppose we want to have the start value 100 stop value 103 and we want the increment with the step of 1. So step equal to 1. So now the numbering will start from 100. After that again the data frame is printed. So let us run the program. So here the index now starts from 100 instead of zero. The start value is 100. The step value is one. So it will start from 100 1 0 1 and 1 02. Now again if you want to reset this range index then further we need to update the code and use the inbuilt functionality reset index within its argument drop equal to true, in place equal to true. So here drop equal to true removes the previous index completely. Now let us again run the program. So finally you can see that the resetting to default index we will get our default values. So in today's session we explored pandas indexing its role in data frames and how to [clears throat] customize it. We also saw its practical use. So some of the key points that you need to keep in mind are the default index in pandas is integer based. Custom index can be set using any column like names or ids. range index are useful for sequential numbering and engineering databases benefit from meaningful indexes like component ID and many other useful names. So thank you for joining today. Keep practicing and see you soon in the next session. Hello everyone. In our previous sessions, we learned about how to create and index pandas data frame. Now we will focus on how to view and analyze data in pandas. This is crucial for understanding the structure of data sets before performing operations on them. Data frame analysis is important as it helps us to understand data structure before processing. It allows quick inspections of large data sets and it is useful for detecting missing values and data types. When working with large data sets, it's inefficient to print the entire data frame. Instead, pandas provide functions to quickly view parts of it. And the some of the functionalities are head, tail, and info. The head function displays the first few rows of a data frame. So for the head functionality within its argument, we will pass the number and it will print the n number of rows that are passed as an argument. If we do not pass any value, it will print five default rows. Same way tail function shows the last few rows of a data frame based on the provided number. If we have not provided any number then it will print the last five rows. And the last info function provides a summary of the data frame including column names, data types and missing values. To understand that, let us go to the VS code and consider one example. Here one data set is provided having the columns component, material and weight and its relevant data is provided in the format of list. This data is passed into the data frame. Now suppose we do not want to print all the data. In place of that we want to print first three rows only. So for that we will use the functionality within print function DF dot head and within its argument three is passed. So it will print the first three rows of the data frame. Now in place of that suppose we want to print the last two rows only. So for that we will type df.tail and within its argument we have passed to and to check the information of the data frame we may directly use the functionality df do.info to check the output. Let us run the program. So first you can see that it is displaying only three rows of the data frame that is bolt steel 10 nut brass and five and washer aluminium and three but remaining data is not printed in the second with the tail functionality it will print only last two rows of the data frame that is pin copper and seven and rivet steel and eight. Next info functionality provide the information about the data frame that is the range index is six entries are from 0 to 5 that is index position is from 0 to 5. It has total three columns. The index are 012 columns are component material and weight. The nonnull count are 6 66. That means it represents that there is no missing value. The data type for these columns are for the first two object and for the weight it is being the int 64. So the total data types are in 64 one times and the object two times and the memory used with this data being the 276 bytes. Now suppose if we have not provided the argument in the head and tail functionality then by default it will consider the five rows from the starting or five rows from the last. So again let us run the program. So here you can see that first five rows are printed and then last five rows are printed and the information data will remain same. So in today's lecture we learned how to quickly analyze a pandas data frame using head tail and info functions. These functions help in understanding data set structure before performing further manipulation. In our next session we will explore how to manipulate the data frame data. Thank you for joining this session. Keep practicing and see you soon in the next session. Hello everyone. In our previous lectures, we learned how to view and analyze data frames. Now let's explore how to manipulate them by adding, removing, and renaming rows and columns. This is crucial when working with real world data where we often need to clean and modify data sets before analysis. So data frame manipulation is important as it allows data cleaning and restructuring. It helps in customizing data sets for specific task and it enables efficient data analysis and visualization. So to understand that let us go to VS code. Here for the reference a sample data frame is provided. It is having the columns component material and weight. This dictionary data is converted to data frame and this data frame is printed. So first let us run the program to check the output. So here original data frame is provided with the four rows and four columns. First being the index then component material and weight. Now suppose in this data frame we want to add the new column. So for that we need to assign values to the new column with name. So we will type df within square bracket new column name that is price and the values for this column being 50 30 70 and 20. So with the price label these new values will be added to our data frame. Let us display this updated data frame. Run the program to check the output. So here after adding the data frame new column is added with the label price and with the given values. So here directly assigning values creates a new column. Column values must match the number of existing rows that one need to keep in mind. Now next suppose one want to add a new row and to add a new row we are having the functionalities log or append but these are depreciated in new pandas version. So it is preferred to use the inbuilt functionality concat. So for that we will type new row equal to the data being component is bolt material is steel weight 50 and the price 10 and all these data is created in the format of dictionary. Now to add these in existing data frame we will write pd dot concat. We want to add it into the existing data frame df pd dot dataf frame. within its argument we will pass our new row as an list and a comma ignore index equal to true. So here this pd.com concat is the preferred method for adding rows and it is also suggested to set ignore index equal to true to maintain the clean index. So this will add the new row. Now to check the output again let us print the updated data frame and run the program. and the new data added is bolt steel 50 and 10 in the respective columns. Now next let's see how to remove unwanted data from the data frame. Suppose we want to drop a price column and for that we need to use the inbuilt functionality drop. So we will type df equal to df dot drop. We want to drop the columns. So columns equal to the label of that column within square bracket. So we want to drop the price column. So we will type its label. So this columns equal to price ensures only the specified column is removed. And here keep in mind that the original data frame is not modified unless reassigned. So here we have reassigned the df.trop to original df. Again let us print the updated data frame and run the program. So here you can see that data frame after dropping the price column these price column is removed and the remaining data is printed. Next suppose we want to drop the row with the index two. So for that we need to type df equal to df dot drop and here we will provide the index equal to index value. So here index equal to two refers that row at the second index position gets deleted. Here keep in mind that index must match an existing row if needed. After dropping the row, let us again print the updated data frame. Let us run the program. So here you can see that the index available are 0 1 3 and 4. The row available at the second index is deleted. Now if needed you can also reset the index using the df dot reset index. And here we will keep drop equal to true. And that we have already understood in our previous session. So suppose here we want to reset the index. So we will type df equal to df dot reset index and drop equal to true. Now run the program to check the output. So here you can see that now index is reset and after deleting the row with index two it will reset the index positions. Next, let's learn how to rename rows and columns for better readability. Now, to rename the column, we will use the inbuilt functionality rename. So, suppose we want to rename the column component and weight. So, we will type df do.t rename within its argument columns equal to within curly bracket. Now, we will rename the data. So, component colon part name. So, the component will be renamed with the part name and the weight will be renamed with the mass. So the format is columns equal to within its curly bracket old name colon new name. Let us print the updated data frame and run the program. So here data frame after renaming the columns the component is renamed with the part name and the weight is renamed with the mass. Next let us understand how to rename the row indexes. And for that we need to type df do.t dot rename within its argument index equal to within curly bracket again we will provide old index colon new index so 0 col a 1 col b 3 col c and 4 col d. So it will replace the old index with the new index label. So using this concept row index can be changed to the custom labels. Let us again print the updated data frame to check the output. So run the program here you can see that at the final row index are changed and they are renamed as A B C and D. So I hope you got the idea how to add, remove and rename rows and columns. So in today's lecture we covered essential data frame manipulation techniques that are adding, removing and renaming rows and columns. These operations are crucial for preparing data sets for analysis. In the next session, we will explore in detail about pandas indexing and slicing. So, thank you for joining today's session. Keep practicing and see you soon in the next session. Hello everyone. Today we are diving deeper into the most powerful feature that is indexing and slicing. These operations allow us to efficiently access and manipulate data within data frame. Understanding how to use lock and eyelock functionality properly will make your data analysis task much easier and more efficient. This indexing and slicing is important as it helps in selecting specific rows and columns for analysis. It allows efficient data filtering and subsetting and it is essential for handling large data sets in real world applications. Before we explore lo and let's revise how to access columns in pandas's data frame. So as an example sample data frame is provided and this dictionary data is converted to the data frame and it is printed using inbuilt functionality. Let us run the program to check the sample data. So here five columns and four rows are available. Now suppose we want to access a single column named component. So we may print df and within its square bracket we will provide the label that is component. So it will print only data related to the component and its index position. So let us run the program. So here the index positions and the component data are printed. [clears throat] So here you can see that it returns the pandas series. Now next we need to understand again two inbuilt functionalities that is log and iO. So to understand that let us go to the presentation. The first LO functionality is known as the label based indexing. To use the LO functionality we will type LO within square bracket we may provide row label, column label. The second is the ILO functionality and that is the integer based indexing. So for that we may type and within it square bracket row index, column index. So in these both functionalities you may get the difference that LO is available for label based indexing and eyelock is available for integer based indexing. Now let's explore LO functionality. For that again go to VS code. Now here suppose we want to access a single row using LO functionality. We will type DF do.log and within it square bracket 1. So this will consider that we are referring to the row with the index level one. Let us run the program to check the output. So here you can see that row with index level one is having component bearing material brass weight 150 and the price 30. The name of this row is one and the data type is object. Now next suppose we want to access the entire material column using this functionality. So we need to type df do.log within it square bracket. First we refer the colon and we are not providing any values. So it refers to the all data of the row. Comma we want to consider only material column. So within double quote the label provided is material. So this will select the entire material column. So it will give us the output the data of all entries available within this material column. To check the output let us run the program. So here you can see that the labels and the data of material column are provided. The name of the column is material and the data type is object. Next suppose one want to access the specific cell using this lock functionality and for that suppose we want to access second row and within this second row we want to access the data of weight column. So we need to type df.lo Outlook two refers to the label of the second row, weight refers to the column name. So it will give us the data from the second row and from the weight column it will print the output 320. Run the program to check the output. So here we are getting the output 320. Next we may also access the multiple rows and specific columns using this lock functionality. So for that we need to type suppose we want to access 1 2 3 row and two columns component and weight. So we will type df.log within it square bracket 1 col 3 comma within list format component comma weight. So it will print the data of rows with the label 1 2 and 3 and the data of column component and weight. Run the program to check the output. So here you can see that the rows printed are 1 2 and three and the columns printed are only component and width. Here keep in mind that this dot log includes the end point meaning row index three is also selected and as you can see in the output. Next we may also filter the data using this log functionality. So suppose we want to print the rows which are having the weight greater than 100. So for that we need to type df do.lo within its argument again we want to access the specific rows. So df within square bracket label that is weight and the value we want to consider greater than 100. So it will select all the rows which are having the weight greater than 100 and that will be printed on the screen. So run the program to check the output. So here you can see that the data is filtered and all the rows are printed which are having the weight greater than 100. So here you can see that this dotlo supports boolean indexing allowing complex filtering operations also. Now next let's look at the functionality that is integer based indexing. Suppose we want to select a single row using these functionality. So we need to type df do iillo within it square bracket 1. So it selects the second row that is having the index one. Let us run the program to check the output. So here you can see that the second row with the index one is selected and all its datas are printed. To select the single column using iO functionality again you need to type df do.log. We want to select all rows. So column, 2. So it will select the third column for all the rows. Run the program to check the output. So here you can see that the third column its name is weight data type is in 64 and its index positions are considered. So all the rows for this third column are printed using this functionality. Again you may select any number of rows and columns you want to print. So suppose we want to access rows one and two and column 0 to 1. So we need to type df.lo I log for the row 1 col 3 comma for the column 0 col 2. Here keep in mind that iO excludes the end point meaning row index 3 is not included. So as we want to select rows 1 to 2 we have mentioned 1 col 3 as 3 is excluded. Let us run the program to check the output. Here you can see that rows with the index label 1 and two and the columns with the index 0 and one that is component and material are selected and printed. In this case for the row index three and for the column two these two are excluded from the data. So I hope you got the idea how to make use of this log and functionality. Now as we understood this lo and functionality let's compare them side by side to get the clarity. So this dot lock functionality is the label based indexing whereas is the integer based indexing.lo functionality includes the endpoint in slicing whereas dot iillo excludes the endpoint in slicing. The boolean indexing that is filtering is supported in LO functionality but it is not supported in the ILO functionality. So in today's session we explored indexing and slicing in pandas using these lo and these methods allow us to access filter and manipulate data efficiently. Mastering them will significantly enhance your data handling skills. So thank you for attending today. Keep practicing and see you soon in the next session. Hello everyone. Today we are going to discuss one of the most fundamental aspect of data analysis that is selecting data. When working with large data sets, efficiently retrieving specific rows and columns is important. In this session, we will explore various ways to select data using query and filtering based on list. Data selection is important as it helps in extracting relevant information for analysis. It improves data processing efficiency and it allows for advanced filtering and manipulation. We have already understood how to access data using basic indexing and slicing techniques. We have also understood we can pass multiple columns as a list of column names. Next, we also explored log and functionalities to select data. Now we need to understand how to select the specific rows or columns based on the specific criteria. So for that we need to filter rows based on the specific conditions. To understand that let us go to the VS code for the sample dictionary type data is provided having the key component material weight and price. This dictionary data is converted to data frame and it is printed using the inbuilt function. Let us run the program to check the original data. Now suppose we want to select a component heavier than 100 g. Now for this we need to use the boolean indexing and it returns only the rows where the condition is true. So here we need to type df square bracket within these again we need to check condition for the weight. So df again within square bracket label weight and if it is greater than 100 we need to print that rows. So it will filter the rows having the weight greater than 100. To check the output, run the program. So here filtered rows are printed having the weight greater than 100. Next suppose we want to select the rows where the price is more than 30. So here we will understand new function that is query and to use that function we need to type df do.query within its argument we will write the condition. So within double quote is we want to mention the label. So we will mention the label within the single quote. So price that is greater than 30. So it will consider all the rows having the price greater than 30. So you can see that this query is more readable than the boolean indexing. And the major advantage of this is it supports the multiple conditions also. To check the output let us run the program. So here you can see that the rows are filtered having the price greater than 30. Now next suppose we want to select the rows for which weight is greater than 100 and price is less than 50. So if we want to use the multiple condition then at this point this query function is also useful. So for this we need to type df dot query within double quote weight greater than 100 symbol and and price less than 50. Here keep in mind that within this double quote whatever label we want to select that will be mentioned within the single quote. So this query select the rows having the weight greater than 100 and price less than 50. To check the output let us run the program. So here you can see that there is only one row which satisfies this condition. So this data is selected and printed on the screen. We can also select rows where columns contains values from a predefined list. So for that we need to follow the process. First we will select the components that we want to select that is within square bracket we have mentioned gear, sub. It represents that we want to select the component that are either gear or sub. Now for that we need to use the functionality is. So we need to mention df within square bracket inside that again we want to select the list component. So df square bracket component dot is in. Now within its argument we will pass the component that we want to check that is gear and shaft. So within this we will pass this list selected components. So it will select the row which is having the component gear or shaft. Let us run the program to check the output. So here you can see that only two rows have been selected having the component gear and so this een requires the argument list and it is used for filtering rows where values matches a list. So in today's lecture we explored various ways to select data in pendance. In previous sessions we already learned about indexing, slicing using log and log and in these we understood filtering with conditions and using query function. These methods are essential for efficient data manipulation. So I hope you got the idea how to use these functionalities to select the data. Looking forward to see you all in our further session. Till then thank you. Hello everyone. Today we will explore two important pandas functionality that are crucial for organizing and cleaning data. The first one is multi-indexing and it is used for multiple level of row indexing. The second is handling duplicates and it is used for identifying and removing duplicate values to clean the data sets. These concepts are widely used in real world applications especially in data analytics, finance and engineering fields where large data sets require structured indexing and cleaning. So these multi-indexing allows us to create hierarchical indexes for our data frame making it easier to store and retrieve complex data. Instead of having single level index, we can have multiple levels such as country is connected to city. There are two possible ways to create a multiple index that is using tpples or list. To understand that let us go to VS code. So for your reference here data set containing population and GDP data for different cities in two countries is provided. We will use tpples to create the multi-index. So as you can see index equal to pd dot multi-index dot from tpples within round bracket we will provide the list of tpples. So within square bracket the tpples are provided India comma delhi India comma Mumbai comma USA New York and USA comma Chicago and the names for these index are names equal to country comma city. So for each tpple country being India, India, USA, USA and the city being Delhi, Mumbai, New York and Chicago. Now suppose we want to create the data frame having the two columns that is population and GDP. So data equal to dictionary is created population with the values and GDP with the values. Now using this dictionary data frame is created. So pd dot dataf frame within its argument data comma custom index is created and that is index equal to the name of variable that is index. So index equal to index. This created data frame is printed using the print function. Now suppose if you want to access all the cities in India from this data frame. So we will type print df.log and within its argument we will pass India. So it will access all the cities connected with the country India. Next suppose we want to access a specific city New York. So for that we will type df.lo from country USA we want to access the New York. So we have mentioned New York. So it will provide all data related to the New York. Next suppose we want to create the multi-index data using arrays. So we will store the data into the arrays. So array is equal to within square bracket two one-dimensional arrays are provided. So first represents the country and the second represents the city. So first is India, India, USA, USA. The second is Delhi, Mumbai, New York, Chicago. Now to create a multi-index we will create index equal to PD dot multi-index dot from arrays. within its argument we will pass the arrays comma names equal to country city. Next suppose we want to provide one column that is population. So pd dot data frame within its argument data provided is population with the values and index being the custom index. So index equal to index and then after again this multi-index data is printed. To check the output let us run the program. So here you can see that the first index is country having the data India, USA. Second index is city having the data Delhi, Mumbai, New York and Chicago. And for these two columns populations and GDP are mentioned as we have accessed all cities in India by passing the label India. So it will print all the data connected to the India country. So it will print the city and the population and GDP data of the Indian city. Next we have access the data using country and city name. So it will print all the data related to the specific combination. So we are having the USA and New York and it is having the population 8 and GDP 1800. So it will print population 8 GDP 1800. The name of this data is USA, New York and the data type is in64. Next again using the arrays concept data frame is created. It is having the index country and index city and only one column is added that is population. So here also you can see that the multi-index are provided. So using these functionalities from tpples or from arrays one can create a multi-index when we have separate list. Next let us understand how to manage the duplicate data from the given data set. In a real world data sets, the duplicate values can arise due to data entry errors, systematic repetition in logging or merging data sets from different sources. To identify and remove duplicates, pandas provide functions like duplicated or drop duplicates. For your reference, one dictionary data is provided. This data is converted to the data frame and then original data frame is printed. Here you can see that there is a duplication in the name, there is duplication in the city also and there is duplication in the age also. Now suppose first we want to find the duplicate rows. To find the duplicate rows, we can use the inbuilt functionality duplicated. So here you can see that we have stored the answer of duplicate rows into the variable duplicates that is equal to df dot duplicated. So this provide the answer for each rows in the format of boolean that is it may be true or false. This function check the data of one row in comparison with the previous rows and if all the data with the previous row match then it says that the data is duplicated. So it returns the value true for that row. Next suppose we want to check the duplicate based on the name column. So for that we may type duplicated name equal to df do.d duplicated within its argument we will pass subset equal to within square bracket name. So now it will consider only column name. So it will compare the name again it will compare the name with the previous name. If it matches then it returns the true as it returns the false. Next suppose we want to remove the duplicate rows. For that we may just simply use the inbuilt function drop duplicates. So here we will store the answer into df_clean equal to df dot drop duplicates. So it will remove the duplicate rows. But here keep in mind that it will keep the first occurrence and remove the all remaining occurrence. Now suppose we want to remove the duplicate and keep the last occurrence. So for that we need to provide the argument into this function such that df dot drop duplicates within its argument keep equal to within double quote last. So it will remove all the duplicates but it will keep the last occurrence. Now to check the output let us run the program. Here you can see that the original data frame is provided. Next we have used the function df do.d duplicated. So it will check for the rows if any duplicate row is present or not. So here you can see that zero false as it is the first row that will be always considered as a false. Then one false then for the two you can see that amid 25 Delhi this data is already available within the first row. So this third row is duplicate. So at the third row it is mentioned true. Same way for the fourth row the value is John 22 Pune that is new so it is represented false and for the last row again Sara 30 Mumbai this data is previously present so it returns the true so from this boolean answer true or false you can see that if any duplicate rows are present or not next we have mentioned the function that checks the duplicate within the name so here you can see that again for the given index position if the name matches or not, it will provide the data. But here it will only check the data for the given name. Next, we have removed the duplicate rows. So here you can see that once we have executed drop duplicates, it will remove all duplicate rows. So here duplicate rows are amit that is at the second index position and at the fourth index position. So it will remove remaining occurrences in the given rows and it will only keep the first occurrence. Next we run the function drop duplicates keep last. So it will remove all the occurrence but it will keep the last occurrence. So here you can see that first occurrence at the index position zero and at the index position one have been removed and the kept rows at the index position are 2, 3 and four. So based on requirement you may select if you want to keep the first occurrence or the last occurrence. So I hope you got the idea that multi-indexing allows structured hierarchical indexing whereas handling duplicates helps in cleaning the data sets. These techniques are widely used in data science and engineering applications to manage the large data sets efficiently. Keep practicing these tool and make utilization of these functionalities in your programs to get the more clarity. Looking forward to see you all in our further session. Till then thank you. Hello everyone. Today we are going to discuss about essential aspect of data handling using pandas that is reading and writing files. We will cover how to read data from Excel file. How to write an Excel data set to a CSV file with specific formatting. Then how to read data from CSV file and how to write CSV data set to another CSV file with different formatting. These operations are crucial in data analysis and pre-processing especially when working with large data sets in industries such as mechanical engineering, finance, healthcare and more. So let us first understand some of the functionalities available to work with the Excel and CSV files. So these Excel files are commonly used in industries for maintaining structured data. Pandas provides read Excel function to import these files efficiently. So to use this function you need to type read excel within its argument as a first parameter you can pass file path. Second you can pass a seat name. It may be a index or name. Third you can pass header and as a header name you will pass header equal to row number to use the column name. Then you can pass the custom column names also. For that you need to type names equal to any required name or you can type none. Next you can pass the index column. So here you need to mention index column equal to any number which column you want to set as the index. Then you can pass use calls also. For that you need to type use calls equal to the column which you want to read. And the last is the data type for the each column. So here the compulsory part is the file path that you need to provide. Remaining all arguments are optional. Now let's understand how to read data from CSV file into pandas. So for that the functionality available is read csv within its argument. First we can pass path to the CSV file. Then separator which is the delimiter and by default it is the comma. Next we can pass the header that is equal to number for which we want to use the column names. Then to assign the custom column names, we can assign the value names equal to any required name. Same way the index column can also be set for which we want to set the index. Next is the use column. So here we will pass the column which we want to read and the last is the data type of each column. So compared to read excel functionality, one parameter is changed and that is the separator. And here CSV only refers to the comma separated values. But other than comma you can also pass many required different separators. Now once we have loaded the Excel data we may want to convert it to CSV file also. And for that pandas provide the another functionality that is to CSV. So within these also first we will call the to CSV function. Within its argument we will pass the path to save the CSV file. then the separator or the delimiter which we want to assign. Next argument is index equal to either true or false. So this represents if we want to write row indexes then we will provide the value true. Next header equal to true or false means again if we want to write column headers then we will pass the value true. And at last columns equal to specific column that we want to write. If we do not want to write any column then we will assign the value none. Let us understand all this functionality using one example. For that go to VS code. Now our first objective is to read the Excel file and currently for the reference purpose I have provided the Excel file in the current working directory and they are the sample data dot CSV and sample data. Excel file. So these both files are present within the same directory. Now to write the Excel file we need to use inbuilt functionality read excel. So we need to type df1 equal to pd dot read excel and the path of the excel as the file is available in current working directory only. So we need to only provide the file name. If the file is available at a different directory then we need to provide the proper detailed path. So here within double quote we have mentioned the file name that is sample data dot xlsx. So this function will read this file and this file will be converted in the data frame format. Now this read data is printed using the inbuilt function print. So let us run the program to check if data is printed or not. So here you can see that the Excel data available within this file are printed over here and the index values are also provided. For your reference let us open the sample data Excel file also. So here you can see that this sample data Excel file is having the three rows with the three different values and the column names are name, age and department. So here we have executed the program and you can see that the by default the columns and the index values are considered to be true. So if we are not defining the value then this function will automatically define the value to be true and import all the data. Now next after reading these Excel file suppose we want to write these Excel data to CSV file then we need to type df1 dot2 csv within its argument first we will pass file name here file name we have provided to be excel_2 csv csv and this file will be created to the current working directory only the value of index is considered to be false means this index will not be considered for the input Separator is considered to be semicolon and the header is considered true. That means it will keep the header value in the file. So let us check the current working directory. Here you can see that no file named Excel to CSV is available. Now run the program to check the output. So here you can see that we have printed the data that it is printed from Excel file and has been returned to Excel to CSV. CSV and the separator used is the semicolon. So again let us check the current working directory. Here you can see that one file is created named Excel_2 CSV. Let us open this file. So here you can see that within CSV data first header is considered then all the three rows are considered and all the datas are separated using the semicolon. Let us close this file. Now suppose one want to keep these index labels also in the CSV file then we need to keep the value of index to be true. So change the value to true. Now again run the program. So further it will write the data to our file. Let us check this file Excel to CSV. And here now you can see that the labels 0 1 and 2 are also added in our CSV file. Let us close this file. Now next suppose we want to read the CSV file and for the reference one CSV file is created with the name sample data and it is having the multiple number of rows having the columns name age and department. So let us read this file using these pandas. So for that we need to type pd dot read csv and the file path which we want to read. So here our file is sample data dot csv. So this file data will be returned to the variable name df2 that is our data frame and then the data frame is printed. So let us again run the program. So here you can see that the CSV data is returned to the data frame and all the datas are printed with the column name and the index values. Here we have not defined any index values. Then this function will consider the default value to be true. Now again we want to write this CSV to another CSV file. So for that we need to type df2 dot2 csv within its argument the file name where we want to store our CSV file then index equal to true separator is vertical line and the header is equal to false. It means it will assign the index values but the column name will not be assigned and then one printing statement is provided. So again let us run the program. Now check the current working directory and here you can see that one file is created with the name CSV_copy and once we open this you can see that the index labels are provided all the remaining datas are also provided but the headers are missing as we have provided the header value to be false and you can see that the separator provided between each data is the vertical line. This vertical line is known as the pipe as a separator here. Here keep in mind that let us close this CSV file here. Keep in mind that index equal to true includes the row index in the output CSV file. Whereas header equal to false excludes the column headers from the output CSV file. So this process is crucial for industries where data is collected from multiple sources such as material testing labs, manufacturing plants or the automo and aerospace industries. By efficiently reading, processing and writing these data sets, engineers and analyst can extract insights, optimize material selection and improve manufacturing processes. So today we covered the essential skill for handling Excel and CSV files in pendas. Mastering these techniques will enable you to work with structured data sets efficiently. Whether you are dealing with experimental results, manufacturing data or material analysis in mechanical engineering. I hope you got the idea how to read and write data to Excel and CSV file using these inbuilt functionalities. Looking forward to see you all in our further session. Till then, thank you. Today we will discuss about one of the most important aspect in pandas that is pivot and pivot table. These techniques are crucial for cleaning and structuring data for efficient analysis. Pivoting data helps in reconstructing data for read for better readability and analysis. Now let's move on to the pivot function in pandas. So this pivoting is useful for reconstructing a data frame by setting columns as a new index levels. So this pivot function recepts data based on unique values of columns. So the syntax of p is we will use p within its argument we can pass index, columns, comm, values. We can define the column to use as a row labels. In index we can define a new columns which we want to use as a new columns in our potted data. And to define the values again we can define different columns to use as a filling data using the third argument values. Let's see an example where we pivot a data set with certain data. So let us go to VS code. Here for reference data in the format of dictionary is provided the key is date and values are provided in the format of list. Same way city and sales data are provided. Then original data frame is displayed using the inbuilt function. Now suppose we want to pivot the data in which we want to define the date as an index, city as in columns and sales as in different values. So for that we need to type df.p P index equal to label date, comma, columns equal to label city and values equal to label cells and then this ped data frame is printed. So let us run the program to check the output. So here you can see that the original data frame is provided with the columns date, city and sales and the common index levels are provided. Now the data frame is pivoted using these date as an index then city as in columns. So city being Delhi and Mumbai and the sales data being the values. So here these entire original data frame is resaved using these new index column and values data. So using this p concept one can resave the existing data frame based on its requirement to collect certain informations. Let us again go back to presentation. So here the p function converts a long format data frame into a wide format. Next is the pivot table and it helps to summarize large data sets into a meaningful tables. They allow aggregation of data using functions like sum, mean, mode, median and count. They support multi-indexing making complex data easier to manage. A pivot table in pandas is a tool that resets data to provide a summarized view using a aggregation functions. Unlike Patt, it can handle duplicate index values and perform calculations like sum, mean and count. So before diving into example, let's understand the syntax of the p table function. So its syntax is pers table. Within its argument, we will pass values, index, columns, aggregate function, fill value and margins. Values refers to the the column to be aggregated. Index refers to the column that we need to use as a row labels. Columns refers to the column to create a new columns from the unique values. Aggregate function is applied for the aggregation and the default value is always mean. Then field value is used to replace the missing data and the margins if true it adds row and column totals. To understand the p table let us again go to VS code and consider one example. So here one example is provided data set of sales records is provided in the dictionary format then it is converted to the data frame and these original data frame is printed. To check that let us run the program. So here default labels are provided then columns are product region sales and profit. Now suppose one want to create a pivot table with the values being sales and profit index being the product columns being the region and we want to use the aggregate function sum. So to use that we need to type df dot pivot table values equal to represent the multiple values we will provide it within the list. So the labels are sales comma profit index is product columns are region and the aggregate function is sum. So now new pword table will be created based on these provided details and this updated pword table is printed over here. So let us run the program to check the output. Here data frame is resaved with the labels being the product that is laptop and tablet. Then the columns are region that is east and west and for both these region the values for sales and profits are represented in this data frame. Next suppose from the data frame we want to show the total number of cells. So for that we need to use the pword table and we need to type df dot pword table values being the cells index being the product columns equal to region and the aggregate function we will consider to be count then the updated data frame will be printed. So let us run the program. Here one can see that the products are laptop, phone and tablet and the regions are east and west. From these above original data frame it can be seen that total number of sales of laptop in the east region being only one entry. So it counts the one. Same way from this multiple row it can be seen that in the east and west region the cell for laptop, tablet and phone represents the only one entry. So for each entry we are getting the count to be one. Next let us take an example to understand the multi-index pivot table. So we can create multi-index pivot table by using multiple columns for index and columns. So suppose we want to have the values being cells then index being product and region and the aggregate function being sum. So for that we need to type df.p P table values are cells index within list product and region and the aggregate function sum and then updated multi-index p table is printed. So let us run the program. Here this p table now has a hierarchical index displaying both product and region together. Here you can see the index is product with these region is connected and then for this combination number of sales are provided. Now in real world data sets we may have missing values and to fill that missing values the field value parameter helps replace the no data with the meaningful values. To understand that let us consider this last example. So we need to type df.tp table values equal to cells index equal to product columns equal to region aggregate function equal to sum and fill value equal to zero. So if any data is missing it will be replaced with zero. So let us run the program here. One can see that all the values are present within this data frame. So no zeros are mentioned with this. I hope you got the idea how to use p and p table within pandas. Now let's compare p and p table to understand their difference. In p [snorts] there is no aggregation function is provided whereas in the p table we get the aggregation support. So we can perform sum, mean, count, median and many different aggregation operations. Pword cannot handle the duplicate values whereas Pword table can handle the duplicate values. Means it will remove all the duplicate data while framing the new data frame. P only supports the single level index whereas P table also supports the multi-index level. So the major important point is P will fail if duplicate value exist whereas P table will handle them using aggregation. So in today's lecture we explored how p and p table work in pandas. We learned how to use p table and p for summarizing data applying aggregation functions handling missing values and creating multi-index tables. Some of the key points that we need to keep in mind are we need to use the pword table when dealing with duplicate values and aggregation. Use multi-index for handling complex hierarchical data and use fill underscore value to replace missing data for better readability. So that's it for today. Keep practicing and I will see you in the next lecture. Hello everyone. Today we will learn how to clean and analyze data set using pandas and this we will understand using example in context of mechanical engineering. So in the aerospace industry, selecting materials for aircraft components is a critical decision that depends on factors like density, melting point, tensile strength, hardness, and cost. However, before making any decisions, we must clean the data set to handle missing values, duplicates, and inconsistencies. We will perform data analysis to summarize and [clears throat] filter the data effectively. So let's go through the code step by step and understand its expected output at each stage. So here some of the data are provided for the aerospace industry and this data is provided in the Excel file named aircraft materials and this file has data as shown over here. So it has multiple materials with the different properties such as density, melting point, tensile strength, hardness and cost. So to access this data first we need to load the data set and here this first line pd excel within its argument file location is provided. File is available in the same working directory. So only file name with its extension is provided. This line loads the data set from Excel file named aircraft materials and it loads it into pandas data frame called df. If the file is loaded successfully, there won't be any visible output. But if the file is missing, you will see some error. So ensure that the file is in the correct location. Now next, suppose we want to display the first five rows of the data set. So for that, we need to use the function df. So this command prints the first five rows of the data set to get an initial look at the data. Now to check that, let us run the program. As you can see first five rows of the data set is loaded over here with the index starting from 0 to four. Here you can observe that melting point has missing value none at these row four and this we will handle later. The data set consist of the materials with their density, melting point, tensile strength, hardness and cost. Next suppose we want to get the data set information. For that we need to type df.info. So this command gives you an overview of the data type and the missing values. Let us run the program. Here we can see that the total entries are 10. Index positions are 0 to 9. Data columns are six and here at the melting point we are getting nine nonnull values. That means there is one missing value. And for remaining data all other columns are fully populated. Next suppose we want to generate a summary statistics. So for that we need to type df dot describe. So this command provides the statistical insights about the data. Let us run the program. So here you can observe that this summary statistic provides the count mean standard deviation the percentile at 25 50 and 75 percentage and the max value and the minimum value for this given data set. So from this data one can check that the mean density is 4.8 g per cm cube. Next tensil strength varies maybe from 90 to 3,500 megapascal and the cost ranges from 5 to 45. So from this data many can get the insights about the data provided. Now as we have observed it has some missing values. Now to check that missing values we may use the inbuilt functionality is null. So for that we need to type df dot isnull dot sum. So it gives the data about how many elements are missing from these different columns. So let us run the program. Here one can observe that melting point has one missing value. For remaining all columns we are having the zero missing values. Now to remove the rows with missing values we need to use the inbuilt functionality drop n. So this function removes the rows with the missing data and it will reduce the number of rows. Let us run the program. So here one can see that row with the index position three is deleted from this given data set. But here the index positions are 0 1 2 and then it jumped to four. Now if one want to have the consistent index then we need to pass the argument that is in place equal to two. So it will update the index position and it will start from three onwards up to the 8. Now next to fill the missing values in the melting point with the columns mean we need to type df dot fill na within its argument we will pass the column melting point. So here we have passed df within its list label melting point dot mean. So it will pass the mean value from this melting point column to these empty data available in the excel. So let us run the program. So here one can see that the melting point is missing for the material carbon fiber. Now once we run the fill na method to fill the data we can see that the carbon fiber is having the melting point and that is nothing but the mean value from this given column. Next to detect the duplicate from this given data set we need to type df do.d duplicated dot sum. So it will give the count that how many rows are duplicated. Let us run the program. So here you will see that the number of duplicate rows are zero because within our data there is no duplication available within this data set. If any duplicate rows are present to remove that duplicate rows we need to type df dot drop duplicates and it will remove duplicate rows from the data set and it will keep only the first occurrence. [clears throat] Let us run the program. So here data set will remain same as there are no duplication so it will not remove any rows. Now suppose we want to count the unique material occurrence then we need to type df within its argument label material dot value counts and let us run the program. So here you can see that the unique count for all these materials are printed and all materials are unique. There are no duplicates present. So we are getting the value one for each material. So in short this tells us how many times each material appears in the data set. Next suppose we want to filter the data we want to select the material with tensile strength greater than 500 megapascal then we need to type df.log within its argument df within its list data we will pass the label tensile strength and then we will pass the boolean operation that is greater than 500. So it will select all the rows having the tensile strength value greater than 500. Let us run the program. So here one can observe that all the rows are filtered having the tensile strength value greater than 500. Next suppose we want to retrieve the first three rows having specific column then we need to type df doiloc within its argument column 3a as a list provided 0a 1 comma 2. It means it will select the rows starting from 0 up to 3 and it will select the columns from 0 to 2. Let us run the program to check the output. So here one can observe that the rows selected are 0 1 2 3 is excluded and the columns selected are 0 1 and 2. So this extracts the material density and melting point data from our given data set. Now next if you want to filter the materials having density less than five and cost less than 15. So we need to type filter materials equal to DF dot query within its argument we will pass our condition that is density less than five and cost less than 15. Here keep in mind we need to provide the same column names as we have mentioned in the data set. So these filters lightweight and cost effective materials like [clears throat] aluminium and magnesium. So let us run the program. It has printed two materials aluminium and magnesium. So with this example we have cleaned missing values and duplicates. We summarized material properties. We filtered high strength and cost effective materials. So these techniques help aerospace engineers in material selection and [clears throat] defining many of the important data from this data set. For the example purpose we have only selected 10 to 11 materials. But in your actual area of work there may be possibility you are having the list of materials. It may be in the range of 1,000 to 2,000. Then again using this concept you can get the insight from your data set. So this process is essential in real world applications where engineer must rely on accurate and well structural data to make informed decision. By mastering data cleaning and exploratory analysis, you can work efficiently with large data sets, identify patterns and gain meaningful insights. I encourage you all to practice these techniques with different data sets and try applying them to real world engineering problems. I hope this session is insightful for you. Looking forward to see you all in our further session. Hello everyone. Today we will discuss Jet GPD for data analysis using pandas. It is an exciting and highly useful topic for anyone working with data. In this session, we will explore how Jet GPD can assist in performing exploratory data analysis and data cleaning using the pandas library in Python. Data analysis is an essential step in making informed decision whether in engineering, finance, healthcare or any datadriven industry. However, data sets often contain missing values, duplicates, inconsistencies and other challenges that must be addressed before meaningful insights can be extracted. This is where JGPD becomes a valuable assistant guiding you through the data cleaning, transformation and visualization. The pandas library in Python provides the powerful tools for loading, cleaning, analyzing and visualizing data and how to utilize that we have already understood in our previous session. So now let's explore how CGP can help automate this task making data analysis faster and more efficient. Now to understand the pendas for data analysis you may ask the chat GPT or provide the prompt and some of the important prompts are listed over here. Now here you can see that some of the important prompts that you may ask that is the first one is how to install and import pandas in Python. So if you are a beginner you are not having any idea. So you may start asking the question from this first one and in similar manner you may ask for the different questions. Let us go to check GPT to understand how it will provide the answer. Now suppose first we want to understand how to install and import pandas. So for that we may ask to jet GPT how to install and import pandas in VS code. So here you will see step-by-step information is provided by the Jet GPT and if you follow this information you will be ready to use pandas in your programming. Now next you can ask how to structure a data [clears throat] set in the pandas. So you may type how can I check the structure of my data set. So here you can see that different functions and its use are provided by the Jet GPT and you may make use of this direct code in your program. So some of the important functions we have already understood in our previous session. Other than this there are many different functions are available that you may explore using these concept of GPT. Now suppose in your data set you are having the missing values. So you can also ask the chat GPT how to manage that missing values. So you may type how can I handle missing values in pendas. So here chat GPT will suggest methods and best practices based on the nature of your data. Same way based on data you may ask how do I remove duplicates from my data set. So for that again it will guide you with step-by-step instructions explaining when to use subset parameters and how to handle large data sets efficiently. Now if you are having the large data set there is also possibility that you may ask that how you can summarize the categorical data using the pandas. So let us type how do I summarize categorical data in pandas. So here Jet GBT will provide code snippets and alternative approach like pivot tables and cross tabs and how to utilize them in our program. So before engineer makes any decision they must clean and analyze this data set. Jet GPT helps streamline this process by suggesting how to remove missing values, how to filter materials and how to detect outliers in the data. By using Jet GPT alongside pandas we save time, improve accuracy and enhance efficiency in decision making. So here you can observe that there are lots of different functions and their usage are provided by the Jet GPT. So in this session we explored how Jet GPT can assist in data analysis using pendas by automating task like data inspection, cleaning, summarization and filtering. Mastering these techniques will help you work more efficiently with data, extract valuable insights and make better decisions in any industry. I encourage you all to practice these techniques using real world data sets and explore how KGPD can assist in solving complex problems. I hope you got the clarity how this pandas library is useful in real world scenarios and in the mechanical engineering
Generated algorithmically for Search Engine
Indexing.