ARANGE( ), LINSPACE( ), LOGSPACE( ) IN NUMPY (ARRAYS WITH NUMERICAL RANGES) - PYTHON PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel so in the previous session we have discussed about the creation of rs with the existing data and in this fun in this session we will move with the a few more functions which are available to create the arrays with the numerical ranges okay so arrays with numerical range right so we know that uh we can create an array by using the array function in number so we are going we are discussing about this module numpy so in order to create an array we have to use the array function and in that function we have to pass some parameters right so the sequential iterables we can pass to the asset parameter to the array function so that an error will be created and now we will see how to create these arrays using the numerical ranges so here we are having mainly the three functions okay the first function is a range function a range function so i will discuss about the parameters later so next line space function line space and log space so mainly we are having the three functions to create an arrays in the numpy with the numerical ranges so in all these three we have to pass the numerical ranges that means numerical range so these three functions will return our array so all these three functions will return array with values in given range and required data type okay so all these three functions we have to pass the numerical range as a parameter and all these three functions returns an array returns an array with the values in the given range so here we have to give the range and within the given range it will return some values and with the required data so commonly for all these functions we have to pass the start index the stop index right and d type detail so these three are the common parameters we have to pass to all these three functions so apart from these three parameters we have to pass a few more parameters so we'll discuss but by default these three are the parameters we are supposed to pass in these functions so this is an optional database data type is an optional so if you are not giving any data type so it will be treated and it will return some data type values okay so if you want to specify some particular data type we have to use this d type argument okay and the start index and stop index so this is normal we know that so within the given range of index values it will take the values it will consider the values and it will store it right so we will move on to the one by one the function one by one so see coming to this a range okay i will arrange everything and we will discuss uh each function and don't worry i will execute all these three functions i will demonstrate all these three functions in the interpreter later after completion of this theory part okay so the first one is a range function array so as we know these functions are in numpy module right first we have to import the numpy module we can give some alias name so numpy as np so we have to call this function by using the alias name np dot array so what are the parameters required first one is the start index start index the second one is the stop index second one is the stop index and the third one is the step size that means the difference between the values okay and the fourth one is the d type d type so these are the parameters taken by the arrange function so this is completely similar to our range function which we have discussed in the iterative statements so in the try two statements we have discussed about the range function so that all the values within the given range will be stored in the some particular uh i mean it will be iterable right so the same thing here in the rs concept we are having some a range function and apart from these three parameters we are having the additional parameter called detect so that means we can give the required editing so if you give if you pass this d type as a integer we'll get all the integer values if you pass this d type as f float we will get the float values right so np dot a range of sum 0 comma 10 comma 2 comma d type is equal to integer okay so this will give all the values between 0 and the 10 which is not included the n index will not be included here right so d type integer so we'll get an array of so 0 2 4 6 and 8 okay if it is a float we'll get 0.2.4.6.8 point okay here we are giving some in the integer value so this precisions will not be there zero to four six eight and this is not a list see the differential how to differentiate the listed array so list will be like this zero comma 2 comma 4 comma 6 comma 8 so these are the comma subtracted values right so these are the comma separated values and this is an area that means a space say space separated values here we should not use the commas so that is the only difference between the list and array so we can differentiate these two things okay so this is how we can use the a range function a simple function okay so now we'll move on to the next one don't worry i will execute the same function in the interpreter so that if you are having any doubt still so those notes will be clarified right next we will go with the second function that is the line space so here also will we have to pass np dot line space line space and the first parameter is common that is start index start index and the second parameter is a stop index so we have to give the stop index and the third parameter is not the step size here we have to give some number okay and then the fourth one is end point so i will give you the description so what is the use of all these parameters the next one is a return step and the next one is a d tag so this will having all these parameters right so start index start index means so we know that start index and stop index okay we have to give the ranges so it will it will consider the values in given range okay given a range that means we can treat it as lower bound lower boundary and this will be treated as upper boundary upper boundary so within the given range we have to get the values next one is a number number is nothing but the return values so how many values we have to get right it returns the number of required values in array so that means if number is two the error will be having only two values if the number is three the error will it will return an array with the three three values if you give a number is equal to five the value i mean the function will return the five values array with the 5 values so this is an optional optional so that means if you are not giving any value here so by default this value will be 50 so that means if you are not giving any value for this number so it will return 50 values okay 50 values so now next one is endpoint endpoint endpoint means whether we have to include the stop index or not so coming to the previous function we have discussed so there is a i mean it will include the start index and it will exclude the stop index but here if the end point is two stop index will be included stop index will be included so the value of stop index will also be added right it will also be included so if it is false stop index is not included okay so pixel stop index will not be included right so if we take the range as some 0 to 10 0 to 10 so if the if it is true the 10 will also be included in the given list and if it is false 10 will not be included so it will be ranges from 0 to 9 right so that's the importance of this end point so by default so this is an also on optional thing this is also an optional thing so by default by default that will be true that means it will include the stop index by default it will include the stop index right so i will show you the demonstration of this function in the interpreter don't worry about that and the next one is the return step red step red step is a written step right so return step will give the difference between the values so if we get uh some number is equal to 5 we will get some 5 values here some 0 2 4 6 and 8 okay so 5 values will be getting so what is the difference between these two okay what is the difference between these two so the difference between the samples or the difference between the elements of the difference between the values will be given as a return step so it returns the difference between values okay so it will return a tuple of the function array function with the parameter i mean with the values comma return step i mean the value okay the difference between the values and this is also an optional this is also an optional okay so by default so if it is a true it is the value will be visible okay the value will be visible if it is a false the value will not be visible not be visible right so we can see the difference and we cannot see the difference if it is a true we can see the difference okay so the difference will also be included in the result and if it is a false the uh the result i mean the value will not be included okay so it's also an optional thing so by default it will be false so by default it will be false by default it will be false so by default if you are not giving any value to this written step automatically the value the return the difference between the values will not be printed in the result okay so this is how we can get the thing okay we can get the return step and the last one is the data type we know that we can include the data type so the required data type will be given so it can be integer or a float right so whatever the data we are giving so that the values will be of the particular data type see start index stop index and number is an optional okay it's an optional thing and this is also an optional and this is also an optional and this is also an optional so we can simply give start index top index and the how many numbers we require so if you are not giving how many numbers we require by default it will be taking as a 50 and it will include the end point and automatically it will not i mean the return step that means the difference value will not be included and the data type will be of float right so this is how we can execute this line space line space so example np dot line space okay line space sum 0 comma 10 comma number is equal to some 5 let it be okay so 5 values and the end point i should i don't want to include the end index so end point is equal to some false so make sure that we should not enclose in quotations right so double conditions simply we have write end point is equal to false and red step is equal to some true so that it will be visible and some d type is equal to integer right so this is an example for creating the line space right so don't worry i will execute this function also and show you the results and we'll move on with the third one and we'll directly move to the interpreter right see the third function is similar to the second function that is the line space the third function is log space np dot log space log space so this is similar but here we will get the log values logarithmic values okay so the starting index the first parameter is start index the second parameter is the stop index and the third parameter is a number so how many values we required that is also same and the next one is the end point [Music] end point here instead of red step we have we are having some base so we have to mention the base by default it will be 10 based and logarithmic base 10 values will be written so if you want to change the logarithmic values we require so we can give the specified base log 2 base okay and the last one is a similar d type d type okay and we know that start index stop index is same we have to give the range so lower bound and upper bound so the start index will be the lower bound lower bound value and the stop index the stop index is the upper bound value and here num is equal to so we can directly go with the num is equal to so num is equal to means the values the number of values required the number of values required and the end point so here also by default by default by default it will be 50 okay by default it will be 50. so this is an optional thing okay this is an optional this is an optional and the end point so this is also it's a true or false right so if it is true end index will be included if it is false end index will not be included so that's also optional so here the default one is true okay it's also an optional thing optional parameter right and the next one is a base so base of log value so we have to specify the base okay and here also the default the base value will be 10 the base value will be 10 okay this is also an optional thing it's also an optional thing and the last one is a d type so here we have to mention either int or a float the required data type which we want to get the values and this is also an optional this is also an optional only one difference means so when compared to the line space and the log space here we get the log values all the log values will be displayed right in the line space the integer values will be given i mean within the given range values will be taken right so all the remaining concept is same so hope you understood these three functions so these three functions are the numerical range functions which are used to create an array right so by using these functions we have to create an array right so hope you understood this three function syntaxes now we will see the practical implementation the demonstration of all these three functions in the interpreter right let's move on to the interpreter hello friends so just now we have seen the different functions to create an array with the numerical ranges and in that we have seen the a range function line space function and the log space function so a range function will take the numerical values within the given range and the line spans functions will give generate the samples within the given range the number of samples and log space is based upon the log values right we will see the implementation part i will open the jupyter notebook and i will show you the execution of these three functions so a range function is similar to the range function which we have discussed in the iterative statements that is range so there it will be accepting three of arguments start stop and step size here also the a range function will also consider these three arguments apart from these three arguments one more arguments will be added that is the four argument uh that is related to the data type so we we can uh get the number of numbers in a given range of required data type so fourth one is the data type d type so first i will import the numpy just i will give some alias name and i have to call all these functions with the help of alias name right so np dot a range of so start and stop we can consider the same some i will give a 2 and we can have the fourth argument d type so d type is equal to i'll give some integers so by default it will be there so if you get it so we'll get an array function an array of list you can observe here it's an array of list so we have while we have studied that in order to create the array using numpy first we have to pass this uh any sequence to the array function right so we have we are supposed to use this array function to create an array so if you create some the same thing and if you initialize that to one variable then automatically will if you print the same array see if you print the array will get the array so here you can see the difference between this result and this result and this is a list of values and this is the list of arrays so what's the difference how can we differentiate the list and arrays so here in the list it's a comma separated values enclosed in the square braces and the array is a space separated values enclosed in a square bases so here we are not using any comma for separating the values so that is that will be treated as an array right so if you observe the same thing see if you execute the same thing by taking the data type as a different float right so float and i i'll just print the array print array so you can observe we'll get the values in a float zero dot two dot or two point four point six point eight point so point is nothing but a precision so that implies that it is an float value right so this is a one function we can create an array using the numerical range that means a range so we will go with the another function that is line space array is equal to np dot so we'll take a array 1 sorry array 1 is equal to np dot we have to call all these functions using the numpy module so as i have given some alias name for this numpy i have to call with the help of the alias name right so np dot line space so line space will also give a range of numericals but it will generate the samples okay it will generate some values and how many values we require that should be given as a parameter so here also the first parameter is the starting index and the last parameter the second parameter is the last index and the third parameter is not step size here we have to give the number of number of values we require so if i give some three values we'll get the three values in between zero and ten if we give five values so we will it will return the five values within the given range zero and ten okay so by default and this is an optional by default it will be treating as a 50. so by default if you give 0 to 10 will get some 50 values okay so i will give some five and next one is the end point there there is a one more called endpoint so that implies whether we have to include the end index or not basically in the range function or in the slicing functions so if you consider some range of values it will include the lower index and it will exclude the end index so that should be decided with the help of this end point and if it is a true endpoint is equal to true that implies we have to consider the end index okay 10 will be considered and if it is a false endpoint is equal to false the 10 will not be considered and within the given range five samples or five where range values will be considered okay so by default this endpoint will be true and if you observe here so if you execute this one so we'll get the values five values so this third argument is values the number of values required values so not the step size so if you execute this one you can observe five values are there so zero point two point five five point seven point five ten point so total five values so here the ten is also included you can observe here ten is also included but whereas by using a range function ten will not be included see you can observe zero point two point four point six point eight point so ten will not be included so but here it will be by default it will be true and if you don't want to include that thing we have to set the endpoint parameters or that so end point parameter as a false so take care that we should not enclose these uh pulse or a true in between the quotations right by default it will be false sorry by default it will be true and if you uh mention it as a false it will the end index will not be included you can observe here end index will not be included only five values we require five numbers so zero point two point four point six point eight point ten is not included here right so if you print it like this by default endpoint is equal to true so 10 will be included so it will return some five values equally separated values right so what is the difference between one value and another value right so if you want to know that thing we have to go with the another parameter so see here we have to go with the another parameter so that is return step return step ret step so if you mention here it has a true by default it will be false so we can't know about that so if it is given as a true if you enter it will return a tuple of the values comma the difference between the one value and another value so here the difference between one value and another value is 2.0 okay you can observe here first zero point next to two point next four point that means equally distributed that the values will be equally distributed so by by default that equally distributed value will be 2.0 okay so by default this return step will be false so so that in the result we can't able to see that difference value and if you want to know what is the difference between the two values we have to set this return step as true so then then we can get the return step the value what actually the difference between the two values right so once again i will show you so if you if if you don't want to add like this that means if you would if you are not giving any numbers so whatever the what we need i mean how many numbers we need by default it will be treated as some 50 okay by default 50 the third argument is number and by default it will be 50. so you can count here so that will get us if some 50 okay so this is a 50 right 50 elements so if you mention the third argument as any integer that many equal number of elements will be created with the equal uh distribution and if if so here we are giving endpoint is equal to false so 10 will not be considered so 9.8 is end point okay so hope you understood this one so here the uh we are we can also have the last uh parameter as a d type okay data type so we can give the data type as an integer or a float okay see we will we'll check it out so d type is equal to integer okay so we'll get the only the integer values so by default it will be followed if you are giving some integer we will get only the integer values so previously so you can observe here see this one we got everything in a float values but here i am giving some d type is equal to integer and getting the values in integer data type okay so this is all about the line space so first one is the starting index second one is the stop index and the third one is the number of values we require so by default it will be 50 and this is an optional and end point whether we have to consider the end index or not so by default it will be true so if you consider it as a false it will it will be not considered not included right and the fifth argument that is a return step so that means uh it returns the value i mean the actual difference between the values in the given range right and the last one is the data type so we can mention the data type so that we can we'll get the result in required data type right this is how we can execute this line space and now we will see the third function that is a log log space okay so log space will give the working of log space is equal to the line space function so it will also accept the similar arguments so but it will return the values of log logarithmic values okay it will return the logarithmic values that is the only difference and here we have to additionally we have to give the log that that means the base value right so we'll see log space and first one is the starting index second one is the end index and the next one is how many values we required so and then the end point is same okay the end point is same so if it is by default it will be true so it will be considered the last indexes will be included and i'm taking this is false so it will not be included and i just want to print the same so you can observe here so we'll get all the logarithmic so here we we have not mentioned any base value so then then the base value default base value will be 10 okay so if you want to change the base value here we have to change as some 2 okay sorry so we can we can have the argument so base is equal to some 2 so that will give we will get the values of base 2 right so we'll get the base values too so we then total number of values we required is 4 so we got only the 4 values okay the base value of two right equally divided values with a base two and end point is false false so 10 will not be included 10 will not be included okay so see so this is how we can get so by default the number will also be 50 here so we we got all the 50 values you know we got all the 50 values we are not mentioning any number right so then we'll get the 50 values so this is how we can create an array by using the log space function so in this session we have seen these three functions so which are used to create an array by using the numerical ranges so first one is a range function then line space function and the log space function and here also the last argument is a data type so d type we can give the required data type also right so hope you understood this session and these three functions and if you are having any doubts regarding these three functions uh feel free to post your doubts in the comment section so that definitely i will try to clarify all your doubts and if you really understood my session like my session share my session with your friends and don't forget to subscribe to our channel thanks for watching thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 7,446
Rating: 4.96 out of 5
Keywords: sundeep, saradhi, kanthety, python, programming, basics, fundamentals, programming concepts, modules, object, import, interpreter, python libraries, libraries, numpy, numpy installation, libraries installation, python IDE, python IDLE, ndarray, ndim, array( ), creating ndarray, n dimensions, numerical python, basics of numpy, numpy introduction, start index, ndimensional, array with existing data, arange function, linspace function, logspace function, numerical ranges, array creation
Id: ixDSXkuiuR4
Channel Id: undefined
Length: 31min 19sec (1879 seconds)
Published: Sun Jul 26 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.