0% found this document useful (0 votes)
9 views4 pages

Jupyter Notebook 1

Uploaded by

RamRakh Yadav
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)
9 views4 pages

Jupyter Notebook 1

Uploaded by

RamRakh Yadav
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/ 4

In [2]: import numpy as np

In [7]: # 0-Dimensional Array


arr1=np.array([57])
print(arr1)

[57]

In [8]: # 1-Dimensional Array


arr=np.array([1,2,3,4,5,6])
print(arr)

[1 2 3 4 5 6]

In [20]: # 2-Dimensional Array


arr2=np.array([[1,2,3,4,5,6], [5,8,11,12,15,17]])
print(arr2)

[[ 1 2 3 4 5 6]
[ 5 8 11 12 15 17]]

In [21]: # Multi-Dimensional Array


arr3=np.array([[1,2,3,4,5,6], [5,8,11,12,15,17], [33,55,77,99,11,22]])
print(arr3)

[[ 1 2 3 4 5 6]
[ 5 8 11 12 15 17]
[33 55 77 99 11 22]]

In [22]: # tells the shape of array


print(arr3.shape)

(3, 6)

In [23]: # tells the size of array


print(arr3.size)

18

In [27]: # 3*5 array with 0s


x=np.zeros((3,5))
print(x)

[[0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0.]]
In [28]: # 3*5 array with 1s
x=np.ones((3,5))
print(x)

[[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]]

In [31]: # 3*5 array with 8s


x=np.full((3,5),8)
print(x)

[[8 8 8 8 8]
[8 8 8 8 8]
[8 8 8 8 8]]

In [32]: # 4*4 array with diagonal 1s


x=np.eye(4,4)
print(x)

[[1. 0. 0. 0.]
[0. 1. 0. 0.]
[0. 0. 1. 0.]
[0. 0. 0. 1.]]

Indexing and Slicing


In [3]: arr=np.array([5,6,7,8,9,10])
print (arr[-4])

In [6]: arr1=np.array([[10,20,30],[40,50,60],[70,80,80]])
print (arr1[0,2])

30

In [7]: print (arr1[1,:])

[40 50 60]

In [10]: print (arr1[:,1])

[20 50 80]

Vector Arithmetic
In [11]: x=np.array([1,2,3])
y=np.array([11,12,13])
print(x+y)

[12 14 16]

In [12]: print(x+5)

[6 7 8]

In [13]: print(x-y)

[-10 -10 -10]

In [14]: print(y-x)

[10 10 10]

In [15]: print(x*y)

[11 24 39]

In [16]: print(y/x)

[11. 6. 4.33333333]

Statistical Functions
In [17]: # max- gives highest value of array
m=np.array([7,8,9,10,11])
n=np.max(m)
print(n)

11

In [18]: # min-gives lowest value of array


m=np.array([7,8,9,10,11])
n=np.min(m)
print(n)

In [19]: #sum- gives addition of array


m=np.array([7,8,9,10,11])
n=np.sum(m)
print(n)

45
In [20]: # prod- gives multiplication of array
m=np.array([7,8,9,10,11])
n=np.prod(m)
print(n)

55440

In [22]: # mean- gives average


m=np.array([7,8,9,10,11])
n=np.mean(m)
print(n)

9.0

In [23]: # median- gives middle value of array (first sorts and then gives middle value)
m=np.array([7,8,9,10,11])
n=np.median(m) #as values are odd so gives centre
print(n)

9.0

In [24]: m=np.array([4,2,3,6,9,7])
n=np.median(m) #as values are even so gives midd
print(n)

5.0

In [26]: # var- gives variance


z=np.var(m)
print(z)

5.805555555555556

In [27]: # std- gives standard deviation of array which is square root of variance
v=np.std(m)
print(v)

2.4094720491334933

You might also like