Hello friends, I hope you all are doing great. As we are working on Raspberry Pi libraries for Proteus these days, so today, I am going to share another awesome library i.e. Raspberry Pi Zero W Libary for Proteus. We have already shared the Raspberry Pi Pico, Raspberry Pi 3 & Raspberry Pi 4 Libraries for Proteus, I hope you have already installed these libraries.
We have only designed the exterior look of this module, it won't be able to read the Python code. You can use this module to design circuit diagrams of your projects or to demonstrate your project in the presentation. Although, just for fun, we have added the Arduino UNO firmware to it. So, you can add the Arduino hex file in it. Something is better than nothing.
So, let's install the Proteus Library and simulate Raspberry Pi Zero:
Where To Buy? | ||||
---|---|---|---|---|
No. | Components | Distributor | Link To Buy | |
1 | Battery 12V | Amazon | Buy Now | |
2 | LEDs | Amazon | Buy Now | |
3 | Resistor | Amazon | Buy Now | |
4 | Raspberry Pi Zero | Amazon | Buy Now |
Raspberry Pi Zero W Library for Proteus
Note: For a better understanding, you should read How to Add a New Library File in Proteus.
As I mentioned earlier, this RPi Zero module in Proteus won't be able to read the Python code. So, just for fun, we have added the Arduino firmware inside. I know it's not that helpful but that's all we have right now. I hope we will design the real Raspberry Pi Zero simulator one day. So, let's add the Hex File in Raspberry Pi Zero W:
Let's clear this thing up one last time, we can't add Python code in this simulated Raspberry Pi Zero, so just to have some interaction, we have added the Arduino Hex file in it. So, we need to get the Arduino hex file.
So, that was all for today. I hope you will enjoy this Raspberry Pi Zero W Library for Proteus. If having any difficulty, ask in the comments. Thanks for reading. Have a good day.
Hello friends, I hope you all are doing great. Today, I am going to share the Raspberry Pi 4 Library for Proteus. In our previous tutorial, we shared the Raspberry Pi 3 Library for Proteus and as we mentioned in that tutorial, these Raspberry Pi libraries will have dummy modules i.e. We have just designed the exterior but these boards won't be able to read the Python code. Although just for fun, we have added the Arduino firmware in these boards, so we can upload the Arduino code in it. As the legends say, something is better than nothing. We have given these boards an unofficial name "Arduino Pi".
You can use these Pi boards to design your circuit diagram or can also use it in your presentation/demonstration of your projects. I hope you will enjoy these simulated Raspberry Pi boards. Before going forward, let's first have a brief overview of Raspberry Pi 4:
Where To Buy? | ||||
---|---|---|---|---|
No. | Components | Distributor | Link To Buy | |
1 | Battery 12V | Amazon | Buy Now | |
2 | LEDs | Amazon | Buy Now | |
3 | Resistor | Amazon | Buy Now | |
4 | Raspberry Pi 4 | Amazon | Buy Now |
So, now let's have a look at How to add this Proteus library and simulate Raspberry Pi 4 in Proteus.
Raspberry Pi 4 Library for Proteus
Now let's design the Simulation of Raspberry Pi 4 in Proteus. As I mentioned earlier, we can't feed Python code to this RPi4 board. So, we have added the Arduino firmware to it. Thus, we need to upload the Arduino hex file in it. Let's attach an LED with Raspberry Pi 4:
So, that was all for today. I hope you will enjoy this Raspberry Pi 4 Library for Proteus and will use it in your projects. Let me know your feedback. Have a good day. Take care!!!
Hello friends, I hope you all are doing great. In today's tutorial, I am going to share a new Proteus Library for Raspberry Pi 3 module. In my previous tutorial, I shared the Raspberry Pi Pico Library for Proteus. Similar to Pico Library, this RPi3 LIbrary won't operate on the Python code. We have just designed the front look to use in the circuit design. Although, we can upload Arduino code to these simulated Raspberry Pi boards.
This Raspberry Pi Proteus Library will have only the Raspberry Pi 3 board in it. We will design the other Pi boards soon. So, let's have a look at How to simulate Raspberry Pi in Proteus:
Where To Buy? | ||||
---|---|---|---|---|
No. | Components | Distributor | Link To Buy | |
1 | Battery 12V | Amazon | Buy Now | |
2 | LEDs | Amazon | Buy Now | |
3 | Resistor | Amazon | Buy Now | |
4 | Raspberry Pi 3 | Amazon | Buy Now |
First of all, we need to download the Raspberry Pi library files, by clicking the below button:
Raspberry Pi 3 Library for Proteus
Note: Look at How to add a new Library in Proteus 8, if you are having any issues.
Now we are going to simulate this Raspberry Pi 3 board in Proteus. We will attach a simple LED to one of its pins. As I told earlier, we have just designed the exterior of this board. It won't read the Python code. We can use it to design circuit diagrams for our project. But just for fun, we have added the Arduino firmware to it. So, we can upload the Arduino hex file in this Pi board.
Now, let's run our simulation to get the results:
So, that was all for today. I hope you will use this Raspberry Pi Library to design your projects. In the next tutorial, I will share the Raspberry Pi 4 Proteus Library. Till then, take care. Have fun!!!
Hello friends, I hope you all are fine. In today's tutorial, I am going to share the Raspberry Pi Pico Library for Proteus. It's a dummy library, we have just designed the display. We can't add the Python Code to it, but we can make it work with Arduino code. A mixture of Arduino and Raspberry Pi, I have given it an unofficial name "Arduino Pi". It's better to have something than nothing. You can design circuit diagrams using this library and can also demonstrate your project in presentations by designing simulations.
So, let's have a look at How to simulate Raspberry Pi Pico by adding this Proteus Library:
Where To Buy? | ||||
---|---|---|---|---|
No. | Components | Distributor | Link To Buy | |
1 | Battery 12V | Amazon | Buy Now | |
2 | LEDs | Amazon | Buy Now | |
3 | Resistor | Amazon | Buy Now | |
4 | Raspberry Pi Pico | Amazon | Buy Now |
Raspberry Pi Pico Library for Proteus
Note: Look at How to add a new Library in Proteus 8, if you are having any issues.
We have tried to keep it small in size so that other components could get more space.
As I told earlier, we can't program this Pico board with Python, which is the actual programming language of this board. But just for fun, we have enabled it to read the Arduino code. Let's design a simple blink example to see how it works:
Now let's run our simulation to check the results:
So, that was all for today. I hope you will enjoy this Raspberry Pi Pico Library for Proteus and will use it in your simulations. If you have any suggestions, use the below comment form. Thanks for reading. Take care!!!
Hello friends, I hope you all are doing well. In today's tutorial, I am going to share a new Proteus Library of ESP32 embedded module. ESP32 is a microcontroller board used mostly in IoT projects. It's a successor of ESP8266 or NodeMCU. We have already shared the NodeMCU Library for Proteus and I hope you guys have enjoyed it.
Proteus software is not capable of handling WiFi or BLE technology, thus we can't implement these technologies in the ESP32 board. Though, you can use its input/output pins to interface embedded sensors and modules. You can also use it to design the Circuit Diagram of your Project.
So, let's have a look at How to simulate ESP32 board in Proteus:
Where To Buy? | ||||
---|---|---|---|---|
No. | Components | Distributor | Link To Buy | |
1 | Battery 12V | Amazon | Buy Now | |
2 | LEDs | Amazon | Buy Now | |
3 | Resistor | Amazon | Buy Now | |
4 | ESP32 | Amazon | Buy Now |
Note: Look at How to add new Library in Proteus 8, if you don't know already.
So, using this ESP32 Library, we have added the board in Proteus software. Now, let's simulate ESP32 in Proteus:
We are going to simulate the ESP32 board by running Blink LED Example. As I told earlier, we can't add WiFi and BLE capabilities in this simulated ESP32 board. So, we are going to select Arduino UNO in the board section of Arduino IDE to get the hex file.
So, that was all for today. I hope you have enjoyed simulating ESP32 board in Proteus software. If you have any questions, ask in the comments. Till the next tutorial, take care. Have fun !!!
Hello friends, I hope you all are doing great. In today's tutorial, I will share a Proteus Library of another embedded module i.e. NodeMCU. NodeMCU is a microcontroller board and if you are new to this board, you should read Introduction to NodeMCU to get your hands dirty. NodeMCU is not present in the components library of Proteus and using this library you can easily simulate NodeMCU in Proteus.
We can't add WiFi and BLE capabilities to our module in the Proteus software, that's why it will just perform the basic functions i.e. sensors interfacing, PWM, I/O control etc. So, you can use it for simple code testing and can also use it to design circuit diagrams of your projects.
So, let's have a look at How to download NodeMCU Proteus Library and simulate it:
Where To Buy? | ||||
---|---|---|---|---|
No. | Components | Distributor | Link To Buy | |
1 | Battery 12V | Amazon | Buy Now | |
2 | LEDs | Amazon | Buy Now | |
3 | Resistor | Amazon | Buy Now | |
4 | ESP8266 | Amazon | Buy Now |
Note: Look at How to add new Library in Proteus 8, if you don't know already.
So, we have successfully added the NodeMCU module to our Proteus software. Now let's simulate NodeMCU and for that, I am going to use the blink example:
Note: As you can see in the above code, we have selected Arduino UNO in the boards' section. As I have told earlier, this NodeMCU module is only going to use its pins, we can't add WiFi or BLE capabilities in the Proteus software. So, while compiling the code, select Arduino UNO board. Something is better than nothing.
So, that's how you can easily simulate NodeMCU in the Proteus software. If you have any questions, please ask in the comments. I will resolve them as soon as possible. In the next tutorial, we will share the ESP32 Library for Proteus. Till then take care and have fun!!!
Hey learners! Welcome to the following lecture on Python, where all the examples are practically explained with the help of the Jupyter notebook. We have been working with the data types for a long time, and now we know all the basics about them. There are certain concepts that are applicable to almost all sequences, but there are some rules for performing this function. Python has many concepts that are unique and simple, and if we talk about the slicing of the data type, other high-level languages such as C++ have the same concept, but Python gives the easiest way to do so. How we will work on different data types to check whether they support the slicing or not. In this way, we can revise the concept that we have been working on so far. Nevertheless, before that, you have to check the list of content given next:
What is "slicing" in Python?
Can we slice any sequence?
What are the methods to use for the slicing process?
How do we use the colon to slice the lists?
Describe the process of using the colon in different ways and slice the sequence.
How do we use the slicing function on the arrays?
Can we use Numpy to slice the sequence?
How do you slice the tuple for slicing the sequences?
We are all familiar with the slicing of bread, and the same concept is related to the slicing of a sequence with the help of different procedures. As we sliced the things and then picked the required ones for our usage, in this lecture we will slice the sequences(that are mutable or immutable in different ways). It is an important concept in programming especially if we talk about Python. There are different ways to introduce the slicing of data types:
"Slicing is a mechanism in Python that allows you to extract a portion (or a subset) of a sequence, such as a string, list, or tuple."
Slicing allows you to extract a portion of a sequence by specifying the start and end indices, allowing you to extract a contiguous portion of the sequence. There are different ways of slicing the data types, and we will go through all the important types that we have learned in this course.
There are certain ways to perform the same operation in a different way while you are programming. This is a plus point of Python it provides programmers to work in uncomplicated ways. People with prior experience in programming will find it super easy to slice the data types. There are two options for using the slicing mechanism mentioned below:
Slicing through colon
Slicing through function
There are still more types and ways to perform these functions, and we will try our best to perform all of you to show you the perfect way for every type of slicing you want according to your requirements. Moreover, it becomes easy to perform the complex problems when you know more than one solution in programming.
The first data type that will be sliced here is the list. We know lists are described by square brackets, and in Python, slicing of the list is a common practice because a large amount of data is stored in the lists; therefore, to perform efficient operations, we need the slicing often. The first example of the slicing of sequences is given next:
This is the first style of slicing a sequence with the help of a colon. It is the simplest way to use the colon for slicing a long sequence, and the following syntax is used in it:
Name=[start;end]
Where,
name = "Name of the sequence declared before using this function."
start= It denotes the starting point for our sequence.
end: The point at which our chosen area must come to an end.
So let's try the example to check the results.
#starting a new list to be sliced
myList = [22,8,11,9,44,11,22,89,4,90]
#slicing the list from the first to the fourth element
result=myList[1:4]
#printing the results
print("The sliced list= ", result)
Hence, only a small portion is obtained as expected.
We have seen a simple example till now but what if we want the variation? Programming is not an easy job and not every time do we need to simply put the portions of a list into different programs, but most of the time we have to pick the specific entries of the lists. For this, Python has another option for programmers. Simply by adding another parameter to the previous case, we can get the variations in the results according to our choice in the following way:
#starting a new birthday party list to be sliced
myList = ["balloons", "party hats", "cake", "candle", "drinks", "plates"]
#slicing the list to get from the first six elements at the step size of two elements
result=myList[1:6:2]
#printing the results
print("The sliced list= ", result)
Hence, in this case, we have seen the list in which the items from the birthday party were saved, and we wanted to get a final list that had the items from the parent list by ignoring the odd indexed elements and printing only the even indexed elements. We have taken this simple example to make sure you get the concept of the difference between the types of slicing discussed so far.
If you have run the previous code, has the question popped into your mind as to what the other way to do so is? Well, yes, as we always say, programming gives you multiple options. If, in any case, the programmer is not able to use the start and end points and wants the whole sequence with steps, the other way to do so is to use the double colon. The simple code is given next:
#starting a new list with a string message in it to be sliced
myList = ["Hello", "we", "are", "programmers"," and", "we", "are", "interested", "in", "Python"]
#slicing the list to get the whole set with three steps till the end.
result=myList[::3]
#printing the results
print("The first four elements= ", result)
Here the procedure is simple and we are getting the required elements according to the need.
Another method to get the same results as in the first case is to use the negative indices. This option may seem different and weird, but in programming, having more options for the same task gives programmers more opportunities to use their creativity in a different way. Let’s prove this with an example:
#starting a new list with the floats in it to be sliced
myList = [23.8,44.8, 120.7, 226.90, 11.7, 118.90,12.55,1.3,77.3,119.1,23.90,31.66,119.4,12.65,11.4]
#slicing the list to get the 6th to 1st element from the end.
result=myList[-6:-1]
#printing the results
print("The sliced list= ", result)
Hence, the programmers can access the data from any side of the sequence easily, according to their needs. This way to slice the arrays has many interesting and fantastic applications in image processing.
The next type to be discussed is the one where only one number and one column are enough to slice the element. The limitation of this method is that the output contains all the elements from the side we started to the ending point, or, as we can say, this is the best way to get the left or right part of the sequence by using merely the starting or ending point and using the colon. The syntax to do this is
Name[start:]
Name[:end]
Here, two cases are discussed. Take the example of a long list where the requirement is to obtain the first five elements only, then the following code will be used:
#starting a new list with a string message in it to be sliced
myList = ["Hello", "we", "are", "programmers"," and", "we", "are", "interested", "in", "Python"]
#slicing the list to get the first four elements from the end.
result=myList[:4]
#printing the results
print("The first four elements= ", result)
As you might expect, the next case is diametrically opposed to the one just discussed. If a person wants to get the second half of the same message, then we have to count ourselves and enter the number of elements that we want to print from the end.
#starting a new list with a string message in it to be sliced
myList = ["Hello", "we", "are", "programmers"," and", "we", "are", "interested", "in", "Python"]
#slicing the list to get the last five elements from the end.
result=myList[5:]
#printing the results
print("The first four elements= ", result)
Hence, the result we wanted to get is here on the screen. This gives a quick and easy way to print the entire length of the sequence.
To slice the sequence, there is a special function that we have also mentioned in this lecture. Using the function is uncomplicated; just feeding the data is in the function's syntax, and the programmers do not need any special declarations before it. The procedure is the same as what we have discussed so far, and therefore, to make things simple, we will use the single code for different types of applications in the slice function.
#importing the double array from the NumPy library
import numpy as NumPy
#decalring the new array
myArray = NumPy.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
#Printing the first to the fourth index of the array using the slice function
result=myArray[0, 1:4]
print("Result= ", result)
#slicing both arrays at the same time and printing output
result=myArray[0:2, 1:5]
print("Result= ", result)
The following points are an extraction of the contents of this code:
The library in NumPy can be used to slice the sequences.
The double array is possible to import from NumPy.
The slicing of an array is possible using NumPy.
It is up to the programmer if he wishes to get the result from the single array or both of the arrays.
The index is used in the slice function, but not the position.
A tuple is another sequence that can be sliced. The procedure is the same, but we will use different ways to use the function in this example.
#creating a new tuple having different data types in it
tuple = ("apple", "balloons", 32.2, "cat",12, "dog", "ear",23,"fruits","guitar","hen",1)
#using the slice function to get the third and fifth elements only
x = slice(3, 5)
print("Element at index three and five= ", tuple[x])
#using the slice function with the steps to get the required output
x = slice(1, 7, 3)
print("Sliced the tuple to get the result using step function= ", tuple[x])
Hence, tuples can easily be sliced using the function, and we have used it here because we wanted to save multiple types of data in the same sequence.
Consequently, it was an informative lecture with a lot of examples and concepts. The start was full of an introduction to the slicing process and why we need the slice function in Python programming. After that, we learn different ways to use the colon for slicing. Although the concept was sometimes discussed in the previous lectures as well as here, we purely focused on the slicing, and it was interesting to see the examples of different data types such as sets, arrays, and tuples. We have a lot to learn in Python, so stay with us for the next lecture.
Hey peeps! Welcome to the Engineering Projects where you are learning the basics of Python in detail. We are working a lot with the arrays as these are important concepts in most of the high-level programming languages till now, the numeric data was used in the arrays but for our practice, we are moving towards the next step where the focus will be on the string data type. The practice is done on the Jupyter notebook and every step is going to be explained well without skipping any concepts but to keep things easy, we are not emphasising unnecessary details and concepts. So, before going deep into the topic, have a look at the list of the contents that will be discussed in this lecture:
What are the strings?
How do we use the string in arrays?
What is the list?
How do we extract the characters from a simple string through indexing?
How do you relate the string array with the list?
How can we get more than one character from a string message without using the array?
How do we add more than one message together by using the concatenation?
What is the best way to access the elements of the string array through indexing?
Can we add more elements of the string array into the already declared array?
How do we remove the elements from the string array?
What is the relation between the string and character in Python and how do you extract the single alphabets from the string using the list method?
All these concepts will be discussed in detail and will be understood by using the coding in Jupyter Notebook.
Here is a quick revision of the concept we have learned so far in this series but it is important to understand the basic definition so that we may understand the difference between all of some basic data types. The string is the sequenced order of the characters. It means that all the meaningful conversations between people and even this lecture are in the form of string. So, in this way, the array, containing all the elements in the form of the string is called the string array. We define it as:
"The string arrays are the specific type of arrays in which all the elements are in the form of string which means it contains the collection of characters in such a way that every element is a meaningful word."
We use the string in our daily life during the conversation and there is no need to explain more because we have used the string many times in our series of these lectures.
If we start from the basics then we have to mention that as the string is a collection of different characters, then extracting the characters from the strings it is quite simple and easy. Why we are associating this method with the arrays? It is because the compiler can read all the characters by indexing them one after the other and that is the reason why we can fetch the characters in Python by using the indexing method. So, have a look at the code for doing this simple task:
#Declaring and printing the string message
str="We are learning Python"
#printing the single character from the message
print("The string message = ", str)
print("The second character is " ,str[1])
print("The tenth character is ", str[11])
#Declaring and printing the string message
str="We are learning Python"
#printing the single character from the message
print("The string message = ", str)
#More than one character
print("The characters from second to ninth index are: " ,str[1:8])
#using only semicolons
print("The first ten index characters are : " ,str[:10])
#out of the range characters
print("The out of the range characters are : ", str[:45])
Here, the following points are to be understood:
More than one character can be extracted from the string using the index.
The starting and the ending number of the range you want to print are to be given in the index with a separation using the colon.
If the programmer wants to print the elements from the start to a certain number, there is no need to mention the zero, and we can start directly from the colon.
By the same token, if the colon comes second and then the number is before it, the compiler will print the character at the index starting from the number till the end of the series of the characters.
In case, the programmer gives the numbers that are out of range then the compiler, instead of throwing the error, prints the whole string with its intelligent working.
We all have been working with the addition of numbers in our tutorials, but today, the good thing about the string array in Python is, the addition of the arrays, even if they have strings in them, is as easy as the other types of “addition processes." The process of concatenation is used for this. We define it as:
"The concatenation is a specific process used for the string to join two or more strings together in a specific manner."
The At this level, there is no need to explain more. Have a look at the following code:
#decalring the arrays with string words
A=["hi", "we", "are", "learning", "Python"]
B=["It", "is", "easy", "with", "theengineering.com"]
#Using the concatenation for the addition
print(A+B)
Output:
In Python, the concept of a string array can be associated with the list because it becomes easy for the programmers to deal with the string as the list has the following feature:
These contain the specific order of the elements, and for the string, if we want to have a specific message, the order is important and it makes our task easy.
It allows frequent changes in the elements so that we may change the message according to our requirements.
Duplication of the element is possible in the list, and in the passing of the message, we observe the same words in single sentences.
Similar concepts are being used here that we have seen when we were learning the numerical problems, but this time, it will be interesting to know the difference between the results with the help of shortcodes.
Once you have declared your string, the extraction of single or multiple strings from the same array is fun. The programmer just has to specify the location, and the element is popped on the output. But there are different ways to do so, and some of them are shown in the code next.
#initializing the array containing the name of programming languages
languages=["C++", "C#", "MATLAB", "ASP.NET", "FLutter"]
#printing the arrays using the index in two ways.
print("\bAccessing the data through index: ",languages[3] )
print("\bAccessing the data through negative index: ",languages[-3] )
#getting the whole array of strings through for loop
print("\bPrinting the whole series using loop")
for lan in languages:
print(lan)
Once the array is made, the good thing is that it can be updated according to the will of the programmer. Let’s say we had an array containing the names of the students in the class; if a new student gets admission or the previous one changes the class, it can be updated easily. In other programming languages, the arrays do not allow the updating of the elements.
#initializing the array containing the name of programming languages
languages=["C++", "C#", "MATLAB", "ASP.NET", "Flutter"]
#appending the new element at the end
languages.append("java")
#getting the whole array of strings through for loop
print("\bPrinting the whole series using loop after appending")
for lan in languages:
print(lan)
#deleting the element from the array of string
languages.pop(2)
#getting the whole array of strings through for loop
print("\bPrinting the whole series using loop after deleting")
for lan in languages:
print(lan)
Hence, the update process is easy to use in arrays. The point that must be cleared here is, the pop function is sued to remove the element from the array and the programmer can not use a string in this place otherwise the compiler will show the error. Only the number of the element can be used in this function, and you must have noticed that it is not the position of the element that we have mentioned here but the index of that particular element.
In other programming languages, characters are separate data types that contain single alphabets and have their own identity and existence. In this way, there must be a specific way to initialize the characters and the strings. Usually, in languages such as C++ and C#, the ways to declare the string and characters are different. Strings are denoted by double quotation marks, and the characters are defined by using single quotation marks around the alphabet. The point that I want to make here is, in Python, there is no concept of single characters, but the declaration of the words or characters, when single or double quotation marks are used, means the string, no matter if it is a single alphabet or the whole message.
In case the programmer needs to convert the string into a single alphabet (the data type is still a string), he uses a simple and uncomplicated function to do so. The code and the output of this specific program with an example are given next:
#initialization and printing of the string message.
myMsg = " Python is easy. "
print("The message before conversion= ",myMsg )
#conversion of the string into alphabets.
myMsgList = list(myMsg)
print("The message after conversion= ",myMsgList )
#removing the white spaces from the result.
myMsgList2 = list(myMsg.strip())
print("The message without white spaces =", myMsgList2)
#printing the message without any single space
myMsgList3 = list(myMsg.replace(" ", ""))
print("The message without any single space =", myMsgList3)
Here, the following points must be known to understand all the operations performed.
The string message is initialized simply, and after that, the programmers can convert it into a list for useful functions.
To convert the whole string message into a single alphabet, the “list” function is used, and the characteristics of the string are converted into the list. Now, you do not have the string on the screen but the list.
In this case, the compiler reads even the blank spaces between the alphabet and shows them in the form of a single character with single quotation marks.
To remove the starting and end spaces, there is a method called "stripping" that eliminates the extra spaces from the message, and as a result, we get only the alphabets with the necessary spaces between them.
Another method called “replace” is used in Python which replaces all the spaces between the message and easily converts the whole message into a series of alphabets with no spaces between them.
There are other such methods that deal with the string in different ways. For example, the conversion of the string into single words is also possible, but for now, we are not discussing it. This is all for today, and we hope you learned a lot from this lecture. The beginning of this lecture included a very basic introduction to the string, and we saw how we can use strings in arrays. Moreover, using our concepts, we have learned many built-in functions, and with the usage of the string, it was easy to understand the concepts. We have seen the concatenation and other ways through which we can modify the strings according to our requirements. We will talk more about the string in our next lecture; until then, happy coding.
Hello students! Welcome to the next episode of NumPy, where we are working more on arrays in detail. NumPy is an important library for Python, and for concepts like integer arrays, it has many useful built-in functions that help programmers a lot. In the previous lecture, the installation and basic functions were discussed and this time, our focus is on the general operations and types of arrays that usually the programmers need during the coding. It is an interesting and basic lecture, and you will learn the following concepts in this lecture:
What are some important types of arrays?
Why are we using NumPy for arrays?
What are zero arrays?
What is the random array?
How can we use the ones array using NumPy?
Is it easy to perform the identity array in Numpy?
Practically perform the arithmetic operations in an array.
How do we find the maximum and minimum values in the array?
If we talk about arrays, it is a vast concept, and many points are important to discuss. It is one of the reasons why we are using the library of numPy and it becomes super easy to work on the arrays using it. There are different types of arrays that we have learned about in our mathematics classes, and some of them are so important that NumPy has special functions for them so that programmers who want to use them do not have to write the whole code manually, but instead, using some important instructions, the array is formed and used automatically according to the instructions.
Understanding the zeros array is not as difficult as its name implies; it is the array that has all the entries set to zero. In other words, the array does not contain any other value than zero. The size and shape of the array are not restricted by any rules; therefore, any size and shape of the array can be declared as a zero array.
By the same token, the code for some types of arrays is simple and easy, so here we want to show you how some programmers can add random numbers to their arrays by using this simple instruction. So have a look at the syntax, and then we will use it in the code:
myArray =zeros((numbers of rows, numbers of columns))
For adding more details to your array, you can use the following syntax:
myArray = np.zeros( shape , dtype , order )
We are using the zeros array for the first time, therefore, to keep things simple, we will use the first method in our program.
random.rand(numbers of rows, numbers of columns)
Both of these require less effort, but with the help of these built-in functions, the programmers feel the convenience of getting the best result instead of using multiple lines of code to get the required results:
import numpy as NumPy
#using the zeros method to print the zero array
print("\bZero array with two rows and three columns " )
zeroArray=NumPy.zeros((2,3))
print(zeroArray)
#using the random method to print the array
print("\bThe random array with two rows and three columns ")
randomArray=NumPy.random.rand(2,3)
print(randomArray)
Here, if you have not noticed the syntax, you must see that both of these have similar syntax, but the numbers of brackets are different. If the programmers do not follow the same syntax for each case (for the simple syntax and for the detailed syntax of zero error), then they will face errors.
Now, here is the task for you, check the other syntax mentioned above about the zeros array and try to find out how you can use the other details in your zeros array.
The next program to perform is also easy to understand if you know the previous one discussed above. This time, all the entries in the array are one. It means, no other entry other than 1 is the shape of the array can be rectangular, square, or any other according to the requirement of the programmer.
myArray =ones((numbers of rows, numbers of columns))
#using the ones method to print the ones array
print("\bZero array with two rows and three columns " )
onesArray=NumPy.ones((2,4))
print(onesArray)
# Declaring the array as a tuple
# declaring their data types and printing the results
onesArray = NumPy.ones((2, 3), dtype=[('x', 'int'), ('y', 'float')])
print("\bDetailed ones array= ")
print(onesArray)
print("\bData type of ones array= ")
print(onesArray.dtype)
Hence, in this way, we have seen two ways to print our ones array to compare the best method that programmers can use according to their requirements.
The identity array is another important type of matrix or array that is used in multiple instructions, and programmers dealing with numbers must know its formation and applications. We know that the diagonal entries in a matrix or array are the ones that have the same value for row and column. In simple words:
i=j
Where,
i=positions of the row
j=position of the column
So, for the identity array, these rules are followed:
All the diagonal elements are one.
All the elements other than the diagonal are zero.
No other number is used in the diagonal array.
The shape of the diagonal matrix is always square, which means the numbers of rows are equal to the number of columns.
Now it's time to move towards its code and output.
myArray=NumPy.identity(integer)
As you can see, only one number is required for this type of array because it is decided that the numbers of rows and columns are equal.
import numpy as NumPy
#declaring an identity array with four rows and four columns.
#printing the simple identity array
print("\bsimple identity matrix")
myArray=NumPy.identity(4)
print(myArray)
#Multiplying the whole array with three.
print("\bAfter the multiplication of the identity matrix with three")
myArray2=3*myArray
print(myArray2)
In this way, we have learned that the multiplication of an array is possible in the code, and it is a simple process just as we do it manually in our mathematical problems.
When dealing with the arrays, there are certain points that are pros of choosing this data type to manage our data. One of the most prominent advantages is the mathematical operations that can be performed on the arrays by following simple and uncomplicated syntax. Here is the list of the operations that you are going to observe in just a bit on the arrays:
This topic is interesting, and you are going to love it because it is simple to perform and easy to understand but is an important concept in Python, especially when using arrays. We all have been working with addition, subtraction, multiplication, and division since our childhood, and now is the time to use them in arrays. There is no need to explain more, so let’s move towards the code.
import numpy as NumPy
#Declaring two arrays for the arithmetic operations.
print("\bElements in arrays")
A=NumPy.array([[12,45,11,7],[23,8,11,90],[12,55,1,90]])
print("A= \n", A)
B=NumPy.array([[76,43,1,90],[43,99,14,11],[12,90,22,55]])
print("B= \n", B)
#Performing the arithmetic operations.
print("\bAddition of arrays \n", A+B)
print("\bSubtraction of arrays\n", A-B)
print("\bMultiplication of first array with the second\n", A*B)
print("\bMultiplication of second array with the first\n", B*A)
print("\bDivision of first array with the first\n", A/B)
print("\bDivision of second array with the first\n", B/A)
As you can see, we have a long list of outputs, and all the operations that we have discussed are self-explanatory. Here, we have seen that all the arithmetic operations can be done from array to array. Moreover, if you look at both types of multiplication and division, the answers are different, and it makes sense because these arrays do not follow the commutative law when dealing with arrays. Mathematically,
A*B!=B*A
Similarly,
A/B!=B/A
In addition to this, you must know that scaler arithmetic operations can be performed on the array that means, an integer or the float can be added, multiplied, divide and subtracted from the whole matrix, and the effect of that number will be observed on all the entries of that particular array.
The next operation in which we are interested in finding the maximum and minimum values in the array. These work great when dealing with image processing and related concepts. These are two different operations, and keep in mind, it seems easy to find the maximum and minimum values in the simple and small arrays, but when talking about the arrays with the order 1000*1000, it becomes almost impossible to find the required value. So without using more time, have a look at the code given next:
maximum_value=numPy.max(Name of the array)
minimu_value=numPy.min(Nmae of the array)
import numpy as NumPy
#Declaring two arrays for the arithmetic operations.
print("\bElements in arrays")
A=NumPy.array([[12,45,11,7],[23,8,11,90],[12,55,1,90]])
print("A= \n", A)
#Finding the maximum Value
maximum=NumPy.max(A)
print("Maximum Value in array = ", maximum)
#Finding the minimum Value
minimum=NumPy.min(A)
print("Minimum Value in array = " ,minimum)
Hence, as you can see, the maximum value occurs more than once in that array, but the compiler only gives us one value. The reason why I am mentioning it is that if NumPy is not used in this case and the programmer does not associate it with the array, the compiler throws the error that there must be another function that has to be used with your particular operation because it takes the array as a tuple. These small details are important to observe because many times, the programmers are stuck into such problems and do not get the reason behind the array.
Determinant=numPy.linalg.det(Name of array)
import numpy as NumPy
#Declaring two arrays for the arithmetic operations.
print("\bElements in arrays")
A=NumPy.array([[12,45,11,7],[23,8,11,90],[12,55,1,90],[11,33,66,1]])
print("A= \n", A)
#Getting the determinant of the array
determinant =NumPy.linalg.det(A)
print(determinant)
If you are confused with the keyword that we have just used here, let me tell you that linalg is the method in Python that is associated with the determinant of the square array. In other words, as we have used ”random” with the rand function above, there must be the use of linalg with the det function. Moreover, never use these functions with other types of arrays. The determinant can only be used with the square matrix.
Hence, it is enough for today. We have seen a lot of information about the arrays in this lecture, and all of these were performed on the NumPy library. At the start, we saw the types of arrays that the programmers used often in the coding. After that, we saw the mathematical operations such as the arithmetic and general operations in the NumPy. We tried our best to use similar arrays for different operations to make the comparison in our minds. All of these were uncomplicated, and throughout this lecture, we revised the basic concepts of the matrices and arrays that we learned years ago during our early education of computers and mathematics.
Hey, peps! Welcome to the new tutorial on the Jupyter notebook. As we are moving towards a higher level of Python, therefore, it is important to understand other ways of doing the same task. As we read in the previous lecture about 2D arrays, this time it is going to be done with the help of a famous library in Python. This time, you are going to learn different, engaging, and advanced-level concepts that not only help you deal with the 2D array but also the installation and working of the unique library of Python, which is NumPy. This lecture is going to be very useful and interesting, and therefore, we suggest you have a glance at all the goals of this lecture.
Getting the introduction to NumPy
Successfully installation of NumPy and knowing different methods for it
Using the arrays with the help of NumPy
Creation, indexing, flattening, and appending of the arrays using NumPy
Knowing the different ways in detail to use these methods.
All of these concepts will be clear to you, and we will move on to more details in the next lecture but for this lecture, it is important to learn the basics.
NumPy is a fantastic library for dealing with numeric data. You must know that a library in Python is a collection of modules that add functionality to a Python program. Libraries are typically distributed in the form of packages, which can be installed with package managers such as pip. If you remember, at the very first lecture of this course, we installed the packages by using pip. The same is the case with NumPy, and this will be clear in just a bit, but for now, you must know that they said that they could include modules that define functions, classes, and variables, as well as algorithms and other services.
NumPy, Pandas, matplotlib, and sci-kit-learn are some of the most commonly used Python libraries. They can be used for a variety of tasks, including data analysis and visualization, machine learning, and web development. Python programmers can take advantage of pre-existing code by using libraries, which can save time and effort when compared to writing everything from scratch.
"NumPy (Numerical Python) is a Python library that adds support for large, multi-dimensional arrays and matrices, as well as a large collection of high-level mathematical functions for operating on these arrays."
It is a fundamental Python package for scientific computing. The good thing here is, Python provides programmers with several ways to perform the same task so that every person may use the best way according to the requirements and expertise of the programmers. In the previous lecture, a simple method was used to perform the two-dimensional arrays, but you must know that NumPy is the second way to do so, which is the reason why we arranged this lecture.
Here comes the action. We are going to work with NumPy, and therefore, the installation process is necessary. The good news is, the programmers do not have to follow the prerequisites when you need to install the NumPy but only Python is enough. So if you are following our previous course, you are good to go with the Numpy. There are two ways to install NumPy:
Installation with the Conda (Advanced level)
Installation with the pip (Beginner’s level)
conda |
pip |
It is preferred by professional programmers. |
It is best for the students and learners. |
It is a cross-language therefore, it can install non-python tools and libraries such as compilers and CUDA. |
It only installs the particular Python on the system. It can not install other libraries rather than Python. |
The source through which the conda installs libraries is its own channel so the resources are owned by the conda itself for the installation. Examples of the channels are defaults and conda-forge. |
The installation is done from the Python Packaging Index (PyPI). Here it is important to understand that PyPI is the largest collection of packages and therefore, it has many features that create ease for Python programmers. |
Conda is considered an integrated solution that is used to manage different types of dependencies and environments. It does not need other tools to manage the packages. |
pip method has to get help from different types of tools to manage and arrange the dependencies and packages. |
Installation with the help of Conda also has different types of methods and for the convenience of all types of users, we are discussing all the basic instructions here.
The best practice for such installations is to use an environment. It means, instead of using the “install” method, the programmers will create the new environment.
conda create -n my-env
Once the environment is created, it's time to activate that particular environment.
conda activate my-env
Another option to perform the same option is to use conda-forge. Many professional programmers prefer this method because conda-forge provides a wide range of software packages, and in our case, NumPy is one of them. If you want to install from conda-forge then the following command is needed:
conda config --env --add channels conda-forge
The methods given above were a little bit tricky, and if the programmer prefers the simplest way, then they must only write the command given next:
conda install numpy
Now, for the installation process at the beginner level, you have to follow the steps listed next. You have to understand that it is recommended to be at this level because all the requirements of this course are designed according to easy and effective ways to code. Hence, the steps given next are enough for all of you:
In the window’s search panel, write the Anaconda prompt.
Here, write the following command:
pip install numpy
Wait for the installation and loading of the library on your personal computer.
Now, to check if your NumPy is working well, go to your Jupyter Notebook.
For this, fire up your Jupyter Notebook by searching for it in your window applications.
Go to the new Python project and wait for the new tab to be opened in your browser.
Note: It is essential to notice that every time the programmers want to use Numpy, they have to import it into the code, and that is the first step of every program where the programmer needs to get help from NumPy.
The typical easy-to-deal-with arrays are similar when we talk about the Jupyter notebook and MATLAB etc. Yet, with the advancement of techniques, better and updated methods have been introduced. The NumPy is a numeric library and to learn its usage, the best way is to deal with the arrays. We hope you know the basics of arrays and their fundamental information; therefore, we are directly starting the practice of arrays. In this way, the students will learn the details of 2D arrays and NumPy side by side.
Creating the array is as simple as what the students have seen in the previous lecture. All the steps are easy, and the comments explain the function of each line.
#importing the numpy
import numpy as numPy
#creating the new array from the imported NumPy library
myArray = numPy.array([[34,8,12,4],[90,5,12,78]])
#printing result
print("The 2D array \n ", myArray)
The output of this code is as expected:
If you want to make an array automatically with the minimal information provided by you, then it can be done with the help of NumPy (such as declaring the shape and size of the array). There are other ways to do so, but using NmuPy gives the programmers relief. It is because NumPy has built-in functions; they just have to associate their array with that particular function and get the desired output.
#importing the numpy
import numpy as numPy
#creating the new array from the imported NumPy library
#using the reshape and arrange functions
myArray = numPy.arange(9).reshape(3,3)
#printing the result
print("The 2D array \n ", myArray)
Here, the important points to be noticed are
The arrange function is used to provide information about the total number of elements in the array. But this must be declared by keeping the shape of the array in mind.
The reshape method has the following syntax:
reshape(numbers of rows, number of columns)
The total number of elements must match the shape so that the compiler may arrange the numbers easily; otherwise, the programmer observes the error.
All of the information is connected with the dot operator in the code.
The values in both these functions are enclosed in parentheses.
The arrangement of both functions is important because if the reshape method comes before the arrange method, there will be a long list of errors and the program will not run.
The indeed method is not new to us. We all know that the index always starts at zero. But in the case, we are discussing, one must know that when an array is declared, the index is not for only the elements but for the whole set of the row.
Moreover, flatting is a special method in NumPy in which the output of the resultant elements in an array is not shown in the form of brackets and single rows, but the programmer gets the real form of the array that we have used in our mathematics and other cases of the array. If these two are not clear to you now, do not worry because after looking at the code given next, all things will be clear.
#importing the numpy library
import numpy as numPy
#declaring my array
myArray=numPy.array([[12,56,33,90],[3,89,12,45],[34,89,12,90],[56,12,9,221]])
#using the flatten function
output=myArray.flatten()
print("The array is now = ", output)
#using the index method to get the third-row
a=myArray[2]
print("The third row= ", a)
The output of this program is given next:
Hence, in this way, we have learned two functions in one code. Here you must know that there are many simple and important concepts about arrays. If we start discussing them in separate codes, then it will become boring and lengthy to learn the small functions and methods.
Once the array is declared, the elements can then be modified. This concept is not applicable to other programming languages, such as C++. Yet, Python gives us this convenience, which is useful for programmers. The appending method is simple and easy, and this code will justify this:
#importing the numpy library
import numpy as numPy
#declaring my array
myArray=numPy.array([[12,56],[3,89],[34,89],[56,12]])
print("\bThe array before appending \n", myArray )
#declaring the second array to be appended
myArray2=numPy.array([[23,89],[12,90],[78,9],[78,11]])
#appending the second array with the first one and printing the result
print("\bThe result of two matrices \n ", numPy.append(myArray,myArray2,axis=1))
Hence, both of these arrays are merged by simply appending them to each other. Moreover, the “axis=1” instruction tells the compiler that the rows of both of these arrays are to be joined in the respective manner; otherwise, the whole array is fixed after the second one. You should check it on yourself.
Consequently, we have learned a lot today. From the introduction of NumPy to the installation of this library, all the steps were discussed here in detail. Moreover, this library was tested by using the array in different ways, such as creating, changing the dimensions, indexing, flattening, and appending the elements. All of these concepts were discussed thoroughly, and there are many more operations on the arrays. Hence, stay with us for more details in the next lecture.