Mathematical functions using numpy

Python Programming Introduction to numpy
12 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.22
List Price:  €93.18
You save:  €27.95
£56.04
List Price:  £80.07
You save:  £24.02
CA$96.09
List Price:  CA$137.28
You save:  CA$41.18
A$106.44
List Price:  A$152.07
You save:  A$45.62
S$94.93
List Price:  S$135.63
You save:  S$40.69
HK$547
List Price:  HK$781.46
You save:  HK$234.46
CHF 63.65
List Price:  CHF 90.94
You save:  CHF 27.28
NOK kr765.05
List Price:  NOK kr1,092.98
You save:  NOK kr327.92
DKK kr486.48
List Price:  DKK kr695
You save:  DKK kr208.52
NZ$116.68
List Price:  NZ$166.69
You save:  NZ$50.01
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,685.71
List Price:  ৳10,980.05
You save:  ৳3,294.34
₹5,844.71
List Price:  ₹8,349.95
You save:  ₹2,505.23
RM331.80
List Price:  RM474.03
You save:  RM142.22
₦98,423.43
List Price:  ₦140,610.93
You save:  ₦42,187.50
₨19,474.95
List Price:  ₨27,822.55
You save:  ₨8,347.60
฿2,584.73
List Price:  ฿3,692.63
You save:  ฿1,107.90
₺2,255.06
List Price:  ₺3,221.65
You save:  ₺966.59
B$356.31
List Price:  B$509.04
You save:  B$152.73
R1,298.99
List Price:  R1,855.78
You save:  R556.79
Лв127.57
List Price:  Лв182.26
You save:  Лв54.68
₩95,950.21
List Price:  ₩137,077.60
You save:  ₩41,127.39
₪261.40
List Price:  ₪373.45
You save:  ₪112.04
₱4,015.50
List Price:  ₱5,736.67
You save:  ₱1,721.17
¥10,912.42
List Price:  ¥15,589.84
You save:  ¥4,677.42
MX$1,187.01
List Price:  MX$1,695.81
You save:  MX$508.79
QR254.79
List Price:  QR364.01
You save:  QR109.21
P956.45
List Price:  P1,366.42
You save:  P409.96
KSh9,168.69
List Price:  KSh13,098.69
You save:  KSh3,930
E£3,313.80
List Price:  E£4,734.21
You save:  E£1,420.40
ብር4,020.93
List Price:  ብር5,744.43
You save:  ብር1,723.50
Kz58,536.36
List Price:  Kz83,626.96
You save:  Kz25,090.59
CLP$65,519.73
List Price:  CLP$93,603.63
You save:  CLP$28,083.90
CN¥505.79
List Price:  CN¥722.59
You save:  CN¥216.80
RD$4,064.05
List Price:  RD$5,806.04
You save:  RD$1,741.98
DA9,434.16
List Price:  DA13,477.95
You save:  DA4,043.79
FJ$159.43
List Price:  FJ$227.77
You save:  FJ$68.34
Q544.12
List Price:  Q777.35
You save:  Q233.22
GY$14,659.33
List Price:  GY$20,942.80
You save:  GY$6,283.47
ISK kr9,804.19
List Price:  ISK kr14,006.59
You save:  ISK kr4,202.40
DH702
List Price:  DH1,002.91
You save:  DH300.90
L1,236.68
List Price:  L1,766.77
You save:  L530.08
ден4,019.08
List Price:  ден5,741.79
You save:  ден1,722.70
MOP$563.89
List Price:  MOP$805.60
You save:  MOP$241.70
N$1,302.92
List Price:  N$1,861.40
You save:  N$558.47
C$2,577.98
List Price:  C$3,682.99
You save:  C$1,105
रु9,357.62
List Price:  रु13,368.60
You save:  रु4,010.98
S/260.83
List Price:  S/372.63
You save:  S/111.80
K271.34
List Price:  K387.65
You save:  K116.30
SAR262.49
List Price:  SAR375
You save:  SAR112.51
ZK1,913.50
List Price:  ZK2,733.69
You save:  ZK820.18
L324.50
List Price:  L463.60
You save:  L139.09
Kč1,630.34
List Price:  Kč2,329.15
You save:  Kč698.81
Ft25,331.89
List Price:  Ft36,189.97
You save:  Ft10,858.07
SEK kr764.93
List Price:  SEK kr1,092.80
You save:  SEK kr327.87
ARS$61,714.55
List Price:  ARS$88,167.42
You save:  ARS$26,452.87
Bs483.86
List Price:  Bs691.26
You save:  Bs207.40
COP$272,553.83
List Price:  COP$389,379.31
You save:  COP$116,825.47
₡35,845.57
List Price:  ₡51,210.15
You save:  ₡15,364.58
L1,730.57
List Price:  L2,472.36
You save:  L741.78
₲523,213.21
List Price:  ₲747,479.48
You save:  ₲224,266.27
$U2,704.33
List Price:  $U3,863.50
You save:  $U1,159.16
zł280.23
List Price:  zł400.34
You save:  zł120.11
Already have an account? Log In

Transcript

So in this lesson, we'll see the mathematical function in NumPy. So let's start immediately by creating a two dimensional array. So before creating a two dimensional array, I'll import a library. Import NumPy as NP. Now, I'll create the array. So I write a RR underscore one, then I'll write NP dot array and within here, write the first element.

And after this, give a comma in square bracket by the second element, now print this now run it. So now this is a array with three columns and two rows. Now we set a program to do the sum of the values within this area. To do this, we use a special function called sum. So NP dot some within bracket right the air, any area Score one, no run it. See, it's 21, which is the value of this a plus two, sorry, one plus two plus three plus four plus five plus six.

That is sum of all the six elements. Now the answer is correct. But doing this addition in this way, it's not useful for us. Suppose you have a sample in your first row and the sample, and the sample the second row now to find the sample sum, that is the sum of the sample distinctly for row one and row two, what we can do is we can just copy this code and paste it here and here, give a comma and right axis is equal to one now run this, see what it will do. So what it does it sum the two rows separately, that is one plus two plus three is equal to six. Four plus five plus six is equal to 15.

In this video, assignments done. Now you can do it vertically also this is done horizontally and now you can do vertical you also how you can do it. So let's just write NP dot sum. And here write a RR underscore one comma axis is equal to zero now run it see it has given you the sum vertically, that is one plus four is equal to five two plus five is equal to seven, and three plus six is equal to nine. Now, we are done with the sum function. Now let's see the multiplication.

So multiplication of certain number of factors. So how we can do it era underscore one right p r or D, this is the function no run it now it gives me 720 is the value of the multiplication of all the numbers present in this area. So 123456 this six numbers multiplication is 720. Now again, here we can also provide the access option. So right AR one dot prod within the first bracket, right axis is equal to zero neuron it. So C is giving you 410 18.

So 41245 cross two is 10, and six plus three is 18. So in this way you got the result, same thing we can do with axis one, so just do it. See, you got six and 120, because one into two is equal to two into three is equal to six, which is this result, and four cross five is equal to 20 and 20 cross six is equal to 120. So I'm getting a perfect reason. Now, after this multiplication function, let's just find out the minimum and the maximum value of this area. So to do that, just write a or underscore one.me and run it See, we got one that is one is the minimum value out of all these six numbers.

Now here also you can provide suppose you want to generate a minimum value for the first room. So what you can do is a RR underscore one here, sorry here in this bracket you have to mention axis axis is equal to zero, run it and see you have got the minimum value from each of the column. So, the minimum value of this column is one, this minimum is two and minimum value is three. So, I've got 123. Now, to get it four rows, what you can do, same thing equal to one neuron and see one comma four. So, here the minimum value is one and here for the second row the minimum value is four.

So, I got one comma four. Now, this is the minimum I know to find the minimum value here is the moon mean function now To find the maximum value, we have to use the max function. So our underscore one dot Max, now just run it, see it gives six because six is the maximum value out of all this six elements. Now here also you can use this access option, but I prefer you to use it by your own here, I'm not sure you just in the same way as we have used in minimum, you can use it in maximum also the same way, and we'll give you the correct prison now. So here we have actually seen that with a max and the minimum function, we often the maximum and the minimum values, but in case we have different data and we want to find the minimum or maximum index value we can use to our function, the arg min or Arma, our max function, so how we can use it.

Let's just do this era underscore one dot r me Now right so it has returned zero this function gives us the minimum value of the world list we can also find the minimum value of each column by doing as follows. That is we can do by using same Okay, now run it it's giving me error why it's giving me error. Because you see what they say numpy.nd every object has no attribute are mean. Why? Because yes, I have misspelled this Be very careful. See, now it is giving zero so the minimum value of this column is that zero index.

Now the same thing you can do for maximum also. So a RR underscore one dot arg max now run it see it written five. So now the maximum value of this total array is that five index now after this minimum and maximum function let's find the average value now to find the average value we use a function called mean me it is equal to average. So era underscore one dot mean run it, it is 3.5. So it is returning you the mean of all these four element that's 123456. Now if you want separate mean for each of this rows and columns, you can use this access option in the same way so I'll just show you one and the rest, you will practice by your own so access is equal to one to run it there is to mean two and five, that is mean for false true and mean for second true.

So now we have found the minimum value that is the average. Now let me show you how you can generate the standard deviation the standard deviation is normal. used by the statistician, well doing statistical tests and everything. So let's just show you how to use it. So error underscore one dot s, t d. This is the function for standard deviation. Now run it and see it's giving me the result 1.7078251.

So this is the value of standard deviation is a huge value. Basically, we, the study in doing some static analysis, we need to find the standard deviation. So here also you can use this axis option to find the standard deviation for each of these axes. So axis is equal to one and C two sine division I've opted. Now let's just move on to the sample variance know how to generate sample variance. So the sample variance is nothing more than the indicator of statistical valuable variability that can be calculated as set in the sample.

So to find the sample variance, we'll just write a RR underscore one dot Via and run this, see we have got the sample variance. Now a very useful function we'll be using here is the click function. So this grid function, let's just first recall the area one era underscore one. So this is the area one now use this clip function era underscore one dot three. And let's just write two numbers to come up and running. And I'll explain you what happened here.

See, see the result. Now what is basically happening here, basically, what this function allows us to do is to format the values as we want. For example, in this case, we told the program that all values that are smaller than two would become two and all values that are greater than four would become four. That's why it is returning 2234 and 444. In this way, we can easily monitor a range of values, for example, have a table of data now the last function that we need Today is the approximation function, which is very important. So to do this approximation function, let me create an array first.

So AR two will be my Errani, which is equal to NP dot array. Now just give you values. So here I'll give a few decimal values. So these are the few missing values that I'm providing and run here. It's shown here and because I've done something wrong, now let's just find what I've done wrong. Yes, I've done yet.

Instead of giving comma here I've given a dot. Now run it Now see, this is the value that we have given an era to now use era underscore two dot round function. See what it has done it is rounded off the values that is this values are now in proper entities that is in around values. Now we can use a decimal option with this round values. So round function so round within this right decimal equal to two and just see what happens see it takes the two decimal places that is this decimal equal to two is referring that how many decimal places to keep so here I've kept only two decimal. Now this decimal part is important because where we'll be doing manipulating data you where currency is stored then then we can use this function because for currency we normally use two decimal place.

So we have come to the end of our lesson today. So in this lesson, we have perform few mathematical options some multiplication minimum, maximum, our mean, standard deviation, variance clip function. function. So all this function we have done are all mathematical functions. So keep practicing. See you in the next video.

Thank you

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.