0% found this document useful (0 votes)
14 views5 pages

Session-23 - Jupyter Notebook

Uploaded by

patilyashyp22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

Session-23 - Jupyter Notebook

Uploaded by

patilyashyp22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

3/9/24, 9:57 PM Session-23 - Jupyter Notebook

In [20]:  1 import numpy as np


2 a=np.array([[3,4,8],[2,5,9],[7,8,10]])
3 b=np.array([10,15,9])
4 ​
5 result=np.linalg.solve(a,b)
6 result

Out[20]: array([-2.26086957, 1.2826087 , 1.45652174])

In [19]:  1 a=np.array([[3,4,8],[2,5,9],[7,8,10]])
2 a

Out[19]: array([[ 3, 4, 8],


[ 2, 5, 9],
[ 7, 8, 10]])

1 2x+3y+5z=15
2 3x+10y+15z=40
3 5x-2y+7z=20
4 ​
5 2 3 5
6 3 10 15
7 5 -2 7
8 ​
9 15 40 20

In [21]:  1 A=np.array([[2,3,5],[3,10,15],[5,-2,7]])
2 B=np.array([15,40,20])
3 result=np.linalg.solve(A,B)
4 result

Out[21]: array([1.95121951, 0.85365854, 1.70731707])

Statistic
In [22]:  1 # 1.Mean
2 # 2.Median
3 # 3.Mode
4 # 4.variance
5 # 5.std
6 ​
7 # outliers=100
8 # [1,2,3,100,5,6]

In [24]:  1 # 1. Mean :-
2 ​
3 arr1=np.array([13,12,45,6,23,89])
4 print(arr1)
5 ​
6 mean=np.mean(arr1)
7 print('mean of array is :',mean)

[13 12 45 6 23 89]
mean of array is : 31.333333333333332

localhost:8888/notebooks/Desktop/Session-23.ipynb 1/5
3/9/24, 9:57 PM Session-23 - Jupyter Notebook

In [26]:  1 # 2. Meadian :-
2 arr1=np.array([13,12,45,6,23,89])
3 print(arr1)
4 ​
5 median=np.median(arr1)
6 print('median of array is :',median)

[13 12 45 6 23 89]
median of array is : 18.0

In [28]:  1 # 3.variance :-
2 ​
3 arr1=np.array([13,12,45,6,23,89])
4 print(arr1)
5 ​
6 variance=np.var(arr1)
7 print(variance)

[13 12 45 6 23 89]
822.2222222222223

In [29]:  1 # 4.std :-
2 ​
3 arr1=np.array([13,12,45,6,23,89,45])
4 print(arr1)
5 ​
6 std=np.std(arr1)
7 std

[13 12 45 6 23 89 45]

Out[29]: 26.974666875815622

In [31]:  1 # 5.Mode >> Most frequent element or value


2 ​
3 from scipy import stats
4 ​
5 arr1=np.array([13,12,45,6,23,89,6,6])
6 print(arr1)
7 ​
8 mode=stats.mode(arr1)
9 print(mode)

[13 12 45 6 23 89 6 6]
ModeResult(mode=6, count=3)

In [32]:  1 arr=np.array([[2,3,4],[4,5,6],[6,6,7]])
2 arr

Out[32]: array([[2, 3, 4],


[4, 5, 6],
[6, 6, 7]])

In [33]:  1 mode1=stats.mode(arr)
2 mode1

Out[33]: ModeResult(mode=array([2, 3, 4], dtype=int64), count=array([1, 1, 1], d


type=int64))

localhost:8888/notebooks/Desktop/Session-23.ipynb 2/5
3/9/24, 9:57 PM Session-23 - Jupyter Notebook

In [35]:  1 arr=np.array([[2,3,2],[2,6,7],[2,6,7]])
2 arr

Out[35]: array([[2, 3, 2],


[2, 6, 7],
[2, 6, 7]])

In [36]:  1 result=stats.mode(arr)
2 result

Out[36]: ModeResult(mode=array([2, 6, 7], dtype=int64), count=array([3, 2, 2], d


type=int64))

In [37]:  1 arr=np.array([[2,2,4],[4,4,6],[6,6,7]])
2 arr

Out[37]: array([[2, 2, 4],


[4, 4, 6],
[6, 6, 7]])

In [38]:  1 result=stats.mode(arr)
2 result

Out[38]: ModeResult(mode=array([2, 2, 4], dtype=int64), count=array([1, 1, 1], d


type=int64))

np.ceil :-
In [39]:  1 # It will return closest integer greater than or equal to given floa
2 # 5.2 >> 6
3 # 3.2 >> 4
4 ​
5 A=np.ceil(5.2)
6 A

Out[39]: 6.0

In [40]:  1 A=np.ceil(3.8)
2 A

Out[40]: 4.0

np.floor :-
In [41]:  1 # It will return closest integer lower than or equal to given float
2 ​
3 # 4.2 >> 4
4 # 3.8 >> 3
5 ​
6 A=np.floor(4.2)
7 A

Out[41]: 4.0

localhost:8888/notebooks/Desktop/Session-23.ipynb 3/5
3/9/24, 9:57 PM Session-23 - Jupyter Notebook

In [42]:  1 A=np.floor(3.8)
2 A

Out[42]: 3.0

Logaritmic function :-
In [43]:  1 import numpy as np
2 ​
3 np.log(10)

Out[43]: 2.302585092994046

In [44]:  1 np.log(1)

Out[44]: 0.0

In [45]:  1 np.log([4,5,6,19,20])

Out[45]: array([1.38629436, 1.60943791, 1.79175947, 2.94443898, 2.99573227])

In [52]:  1 # to calculate antilog use np.exp


2 ​
3 np.exp(0)

Out[52]: 1.0

In [53]:  1 np.exp(2.302585092994046)

Out[53]: 10.000000000000002

Trignometry :-
In [54]:  1 # cosec=1/sin
2 # sec= 1/cos
3 # tan=sin/cos >> 1/cot

In [55]:  1 # 180 degree >> np.pi


2 # sin 30
3 np.sin(np.pi/6)

Out[55]: 0.49999999999999994

In [56]:  1 # cosec 30
2 1/np.sin(np.pi/6)

Out[56]: 2.0000000000000004

In [57]:  1 # cos 45
2 ​
3 np.cos(np.pi/4)

Out[57]: 0.7071067811865476

localhost:8888/notebooks/Desktop/Session-23.ipynb 4/5
3/9/24, 9:57 PM Session-23 - Jupyter Notebook

Degree to radian
In [59]:  1 arr=np.array([0,30,45,60,90])
2 arr

Out[59]: array([ 0, 30, 45, 60, 90])

In [60]:  1 radian=np.deg2rad(arr)
2 radian

Out[60]: array([0. , 0.52359878, 0.78539816, 1.04719755, 1.57079633])

radian to degree
In [61]:  1 arr1=np.array([0.,0.52359878,0.78539816,1.04719755,1.57079633])
2 arr1
3 ​
4 degree=np.rad2deg(arr1)
5 degree
6 ​

Out[61]: array([ 0. , 30.00000025, 44.99999981, 59.99999993, 90.0000001


8])

In [65]:  1 arr1=np.array([0.,0.5236,0.7854,1.0472,1.5708])
2 arr1
3 ​
4 degree=np.rad2deg(arr1)
5 np.round(degree,1)
6 ​

Out[65]: array([ 0., 30., 45., 60., 90.])

In [ ]:  1 ​

localhost:8888/notebooks/Desktop/Session-23.ipynb 5/5

You might also like