0% found this document useful (0 votes)
11 views9 pages

Python NumPy & Matplotlib Tutorial

This document contains code snippets demonstrating the use of the NumPy library in Python for working with numerical arrays and matrices. It shows how to create, manipulate, and visualize numeric data using NumPy and Matplotlib.
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)
11 views9 pages

Python NumPy & Matplotlib Tutorial

This document contains code snippets demonstrating the use of the NumPy library in Python for working with numerical arrays and matrices. It shows how to create, manipulate, and visualize numeric data using NumPy and Matplotlib.
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

1/28/24, 5:22 PM Untitled0.

ipynb - Colaboratory

import numpy as np

a=[Link]([1,2,3,4])
print(a)
b=[Link]([1,2.3,4,5])
print(b)
a1=[Link]([[1,2],[1,2]])
print(a1)

print([Link])
print([Link])
print([Link])
print([Link])
print([Link])
print(type(a))
print([Link])

[1 2 3 4]
[1. 2.3 4. 5. ]
[[1 2]
[1 2]]
(4,)
1
int64
8
4
<class '[Link]'>
<class '[Link]'>

import numpy as np

a=[Link](1,10,5) # (start+end)/n all time add the ratio


print(a)

e=[Link](5)
f=[Link](5)
print(e,f)

a=[Link]([1,2,3,4])
a=a+5
print(a)
a=a-5
print(a)
a=a*5
print(a)
a=a/5
print(a)

b=[Link]([2,3,4,5,6])
h=b
b=b+4
print(b)
print(h)

k=[Link](b)
k[0]=0
print(k)
print(b)

a=[Link](1,10,6)
print(a)

[ 1. 3.25 5.5 7.75 10. ]


[1. 1. 1. 1. 1.] [0. 0. 0. 0. 0.]
[6 7 8 9]
[1 2 3 4]
[ 5 10 15 20]
[1. 2. 3. 4.]
[ 6 7 8 9 10]
[2 3 4 5 6]
[ 0 7 8 9 10]
[ 6 7 8 9 10]
[ 1. 2.8 4.6 6.4 8.2 10. ]

[Link] 1/9
1/28/24, 5:22 PM [Link] - Colaboratory
import numpy as np
b=[Link](10) # 0 to 9
print(b)

c=[Link](5,10)
d=[Link](10,1,-1)
print(c)
print(d)

[0 1 2 3 4 5 6 7 8 9]
[5 6 7 8 9]
[10 9 8 7 6 5 4 3 2]

import numpy as np
a=[Link]([1,2,3,4])
b=[Link]([5,6,7,8])
c=[Link]([a,b])
print(c)

[1 2 3 4 5 6 7 8]

import numpy as np

a=[Link]([[1,2,3,4],[2,3,4,5]])
print(a)
a=a+4 #+,-,*,/
print(a)
print([Link])
print([Link])
print([Link])
print([Link])
print([Link](8,1))
print([Link](2,4))

[[1 2 3 4]
[2 3 4 5]]
[[5 6 7 8]
[6 7 8 9]]
2
(2, 4)
8
8
[[5]
[6]
[7]
[8]
[6]
[7]
[8]
[9]]
[[5 6 7 8]
[6 7 8 9]]

b=[Link]([2,3])
print(b)
b=[Link]([3,3],dtype=int)
print(b)
b=[Link]([1,3],dtype=float)
print(b)

[[ 1. 2.8 4.6]
[ 6.4 8.2 10. ]]
[[ 4607182418800017408 0 0]
[-9223372036854775808 -4616189618054758400 -9223372036854775808]
[ 0 0 4607182418800017408]]
[[0. 0.99999869 1. ]]

import numpy as np

a=[Link]([1,2,3,4,5,6,7,8])
b=np.array_split(a,[3,5])
print(b)

c=[Link]([[1,2,3,4],[2,3,4,5]])
d=np.array_split(c,4)
print(d)

sp=[Link](c,2)
print(sp)
sp=[Link](c,2)
print(sp)

[Link] 2/9
1/28/24, 5:22 PM [Link] - Colaboratory

[array([1, 2, 3]), array([4, 5]), array([6, 7, 8])]


[array([[1, 2, 3, 4]]), array([[2, 3, 4, 5]]), array([], shape=(0, 4), dtype=int64), array([], shape=(0, 4), dtype=int64)]
[array([[1, 2],
[2, 3]]), array([[3, 4],
[4, 5]])]
[array([[1, 2, 3, 4]]), array([[2, 3, 4, 5]])]

import numpy as np

a=[Link]([[1,2,3,4],[2,3,4,5],[4,5,6,7]])
print(a[0:2,:])
print(a[:,1:3])

b=[Link]([1,2,3,4,5,6]) #indexing
print(b[2:-2])
print(b[0:1])
print(b[0:5:2])

c=[Link]([2,2],dtype=int)
print(c)

c=[Link]([3,2],dtype=float)
print(c)

d=[Link](4)
print(d)

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

A=[Link]([2,2],dtype=int)
print(A)

A=[Link]([3,1],dtype=float)
print(A)

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

import numpy as np

a=[Link]([[1,2,3,4],[2,3,4,5]])
b=[Link]([3,4],dtype=int)
print(b)

[[93953841706394 0 0 0]
[ 0 0 0 0]
[ 0 0 0 0]]

import numpy as np
a=[Link]([[1,2,3,4],[2,3,4,5]])
d=[Link]([a,a],axis=0)
print(d)
x=[Link]([1,2,3,4,5,6])
b=[Link](x)
c=[Link](x)
print(b)
print(c)

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

[Link] 3/9
1/28/24, 5:22 PM [Link] - Colaboratory
[2 3 4 5]]
[1 2 3 4 5 6]
[[1]
[2]
[3]
[4]
[5]
[6]]

import numpy as np

a=[Link]([[1,2,3,4],[2,3,4,5]])
a=[Link](4,2)
print(a)

a=([1,2,3,4,5])
b=([6,7,7,8,5])
c=[Link]((a,b)) #[Link] and [Link]
d=[Link]((a,b))
print(c)
print(d)

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

import [Link] as plt

x=([1,2,3])
y=([2,4,6])
[Link](x,y)
[Link]("Score")
[Link]("Match")
[Link]("Day-1")
[Link]()

import [Link] as plt


y=([1,4,9,4,45,3,7])
[Link]( y, linestyle='-', color='b', marker='o')
[Link]()

[Link] 4/9
1/28/24, 5:22 PM [Link] - Colaboratory

x = [Link](0, 3 * [Link], 0.1)


y = [Link](x)
[Link]("sine wave graph")
[Link](x,y)
x = [Link](0, 4 * [Link], 0.015)
y_sin = [Link](x)
y_cos = [Link](x)
[Link](2, 1, 1)
[Link](x, y_sin)
[Link]('Sine Wave')
[Link](2, 1, 2)
[Link](x, y_cos)
[Link]('Cosine Wave')
[Link]()

<ipython-input-79-e3b57ab27b92>:8: MatplotlibDeprecationWarning: Auto-removal of over


[Link](2, 1, 1)

x = [0,2,3,4,5,6,7]
y1=[5,7,9,0,-1,6,8]
y2=[0,6,-2,-9,3,1,9]
[Link](x,y1,label="Day",linewidth=4,linestyle='dashed')
[Link](x,y2,label="Score")
[Link](loc=2)
[Link]()

[Link] 5/9
1/28/24, 5:22 PM [Link] - Colaboratory

import [Link] as plt


import numpy as np
a=[Link]([1,2,3,4])
b=[Link]([0,8,3,0])
[Link](a,b,'>:y')
[Link]("Score")
[Link]("Knowladge")
[Link]("Day-2")
[Link]([Link](5))
[Link]([Link](9))
[Link]([Link](1,5),['a','b','c','d'], rotation=45)
[Link]()
[Link]()

x=[Link](1,11)
y=x*3-2
[Link](x,y,marker='+',markeredgecolor='red',markersize='10')
[Link]()

[Link] 6/9
1/28/24, 5:22 PM [Link] - Colaboratory

import [Link] as plt


import numpy as np
a=[Link]([1,2,3,4])
b=[Link]([9,8,3,3])
[Link](a,b)
[Link]()

a=[Link]([3,6,9,1])
b=[Link]([9,8,3,3])
[Link](a,b,width=0.6,color='pink')
[Link]()

[Link] 7/9
1/28/24, 5:22 PM [Link] - Colaboratory
city=[Link](['Morbi','Rajkot','Halvad','Delhi'])
temp=[Link]([43,34,29,45])
[Link](city,temp)
[Link]()

import [Link] as plt


import numpy as np
a=[Link]([50,20,15,10,5])
b=[Link]([0,0.2,0.3,0,0])
deps=['a','b','c','d','e']
[Link](a,b,labels=deps,colors=['blue','red','pink','yellow','green'])
[Link]("Pie Chart")
[Link]()

import [Link] as plt #W3SCHOOLS


import numpy as np
a=[Link]([1,2,3,4,9])
b=[Link]([6,8,9,0,2])
[Link](a,b,marker='o',linestyle='',color='k')
[Link]()

[Link] 8/9
1/28/24, 5:22 PM [Link] - Colaboratory

[Link] 9/9

You might also like