Introduction to 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 be starting with a library called NumPy. So let's get started. NumPy is a math library for Python. It enables us to do computation efficiently and effectively, it is better than regular Python because of its amazing capabilities. So the first thing I want to introduce to you is the way how to import it. So to import a library in Python, we write input.

Then give the name of the library. So here I read NumPy. Now, as in P. So here we are telling Python that NP is the official reference to the NumPy. Now whenever I need to call the library and just write in I need to refer to the NumPy library. Okay, so first run this. So it is running still, because the star sign is over here.

So as long as the star sign is over here, it's the statement is running. So now it is gone, so it does run perfectly without enter. So I can say that NumPy never is present in my Python. Now the first thing that I'll do is I create an array with a name called era underscore one. So this is a posture so given era one now here, I will create a array using content not by using NumPy library. So to create a area using Python, we need to use a square bracket and within this square bracket and give the Q values.

Six values are provided. This is basically Python list. So Aries It is a list of elements. So write a RR underscore one. Here I'm performing an operation, see what I'm doing class equal to Now run this. See it's giving an error because whenever and create adding using Python nice this operation cannot be performed Okay.

Now, if I run this separately see it can run now if you call this so it can print also, but this particular operation of incrementing the values cannot be performed by using a normal Python array process. So here I use the library NumPy to create an array. So here I write a RR on this tube now here, I'll write NP dot, adding now within brackets and get the values. So one comma two comma three comma four comma five comma six. So these are the values provided. Now press Enter and print type.

So check the type also. And then era underscore to run it, see what it printed, it printed numpy.in the array. So we have created an ND array class of NumPy nd array is a list of an index, just like least which we will now simply con add a data set. So let's see if we can get the program run the operation we tried before. So what we tried before is by to increment the value of era, plus equal to no here will be one I missed this one. So include this one over here.

And if you can run this program you will get an error see the same error anywhere anything that is interpreted is not iterable. Now, the same operation I will perform on this error, so the error that I've created using NumPy library so now here I'll write a RR underscore to plus equal to one and the next one print AR. Now run it see it run perfectly without an error. So, this NumPy library can perform various other things also various additional things also, which are normal Python cannot perform. So what it has done it has incremented each value of this of this particular array by one okay. So what what are the values that are provided 123456 Now, see it has implemented the variable 1234567.

So, in this way we can perform many More operations using the NumPy. So simple addition also we can do my just rikey rr underscore three, then write a RR underscore two plus one. So if I like this what it will do? Let's see era, 3d printing firstly just increases the value by one, and now new value is 234567. And now again, I'm incrementing the value by one See, now it is 345678. So this is a normal addition that we can do.

We can also add to Aires. So how we can do this, this is era three isn't added now we can visit 345678 and era is the array which contains the element 234567. So I'm not adding this to Eric. So error three plus a RR two if I run it, see the red Is 579 11 1315 so directly it is summing up the value between two areas. So now what I'll do is I'll perform multiplication. So it's just now here and perform any multiplication.

So, I use this to area only era to an era three. So era to then give a star sign and write era. So see now it is multiplying the two areas. So the two areas is the first one is the second one is this. So what is done? Two into 363 into 412 42 525 into 636 30 to 742 and seven into 856.

So in this way, the values are got multiplied. Now, if I right here, he is underscore two, and within the square bracket I provide seal, then what we should see what it showed, it showed the first element of the era. To me that is here I'm providing the index number, this is the index number that I'm providing. And it will show you that particular index number when that is that is the element that is present at that index number will be displayed. Now the same thing we have performed in list so I think you will now quite familiar with all these things because list is done. And I think your practice a lot.

So now what I will do is I will write a starting value and we just have a colon. So I think you remember this process I think you remember how what it will give if I use it in list so it will give all the values starting from the index number one, right. Let's also perform the same way. So run it so Starting from index number one, it is providing all the elements of the array. So now we also have a function to identify the number of elements actually in and this function is called shape. So the same shape function will show you that how many elements are there in the ad so how to use it so era to dot shape and what it's showing is showing six so, shape is a specific function of the library, which will not work with Python list.

So if you use this shift function with the Eddie era one it will not work because it is under NumPy library. So let me try one thing. Let me show you if I use with AR one dot shape because This error is not created using NumPy. It is created using normal Python. So here I have written era one dot shape and let's just run it see it gives an error list object has no attribute shape, okay, so it can only run if that particular error is created using NumPy library. So shape is a exclusive function of NumPy library.

Okay, now next thing that we can do is create a list of list. So here we'll be creating a list of list using NumPy library. So how to do that NP dot arrey. Now within this was like a provide a second square bracket, and again, right 123 suppose this is the first list and this is the second list. Now my second is content, character values. So I'll be writing within quotes.

Okay, now, run it, see what it give it give the lead list of lists that is to list within an area now, we can also use a function called average. So, what average do is let me first create an array with the NumPy library. So NP dot array now and right now the NP dot array should be NP dot a range within this first record range zero comma suppose 12 comma two. Now, what is three number mean? The first number is the starting number. The second number is the stock number and the third number is the state number.

So what average does is that it every the number from starting from zero and ending it and instead of two years, is what it means. NPM range zero to l. So, it will return an empty list starting from zero all the way up to 10 but don't include 10 and increment number by two each time, because it will never print the last number. This is the characteristics of an inch, it will not print the last number that you provide, it will print the number just before the last index it will not print, it will just print n minus one. So if you run this see what you have caught it has printed 02468 and something it is now clear with this arrange function to an inch creates an array with this elements that is starting from zero to L and this type of to see thing is a gap of two Between each isn't.

So can we ending this lesson over here, but we continuing continuing with the array of NumPy In our next lesson also. So today we have just started the NumPy library of Python and we learned how to use that library, how to import that library and how to use different function of that particular NumPy library. So keep practicing see 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.