Python

champak
₹2,000.00 ₹300.00
The Python Programming Language at Champak's World
  • 22 students
  • 41 lessons
  • 0 quizzes
  • 10 week duration

Python

Starting Numpy

Numpy is numeric python and it’s a library in python which help programmer to solve complex problem like solving  MATRIX , Complex equations, Solving  high level of mathematics and many more things regarding to mathematics.
For using numpy library we need to import the library on our current file. Here is a syntax of that.

 import numpy as np 

Here as ‘np’ means it is said that we use numpy as np . You can use your name/any name their.
Now some function of numpy and its uses
Declaration of a array and its output

import numpy as np
a=np.array([1,2,3,4,5],float)
print(a)

After running program we get a array.The central feature of NumPy is the array object class

[ 1.  2.  3.  4.  5.]

Moving on ‘in’ statement .This statement shows that the given value is present in array or not. Here is syntax for using that statement.
The result of this statement always come in True or False

import numpy as np
print("Checking that value is present in array or not")
a=np.array([1,2,3,4],float)
print(2 in a)
print( 7 in a)

Here is output of above program

Checking that value is present in array or not
True
False

Concatenation of Array
Concatenation of Array means adding of two or more array in a single array. Here is it’s code to make you clear about concatenation

import numpy as np 
c=np.array([1,3,5,7],float)
d=np.array([2,4,6,8,65],float)
y=np.concatenate((c,d))

Here is output of Concatenation of Array

[  1.   3.   5.   7.   2.   4.   6.   8.  65.]

Creating Array with arange function.From code you will understand better that what is arange function is

import numpy as np 
print("Second way to create array with arange function")
c=np.arange(5,dtype=float)
print(c)

Here is output of arange function

Second way to create array with arange function
[ 0.  1.  2.  3.  4.]

Creating Identity matrix .Code is here

import numpy as np
print("Create Identity matrix ")
c=np.identity(4,dtype=float)
print(c)

Output of this program will give you a Identity matrix

Create Identity matrix 
[[ 1.  0.  0.  0.]
 [ 0.  1.  0.  0.]
 [ 0.  0.  1.  0.]
 [ 0.  0.  0.  1.]]

Numpy help in performing normal Arithmetic like add subs multy. Code is below

import numpy as np
a=np.array([2,4,6],float)
b=np.array([1,3,5],float)
c=a+b
print(a+b,"<-This is result of add")
print(a-b,"<-This is result of sub")
print(a*b,"<-This is result of muti")

Output of above code

[  3.   7.  11.] <-This is result of add
[ 1.  1.  1.] <-This is result of sub
[  2.  12.  30.] <-This is result of multy

Leave a Reply

Your email address will not be published. Required fields are marked *