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

Practical No 13: Px1: Write Python Program To Demonstrate Use of Built-In Packages (E.G. Numpy, Pandas)

The document contains practical exercises demonstrating the use of built-in and user-defined Python packages, specifically NumPy and a custom GPT package. It includes examples of array operations, matrix arithmetic, string concatenation, and generating random integers. Each exercise is accompanied by code snippets and their respective outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Practical No 13: Px1: Write Python Program To Demonstrate Use of Built-In Packages (E.G. Numpy, Pandas)

The document contains practical exercises demonstrating the use of built-in and user-defined Python packages, specifically NumPy and a custom GPT package. It includes examples of array operations, matrix arithmetic, string concatenation, and generating random integers. Each exercise is accompanied by code snippets and their respective outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Practical No 13

Px1: Write Python program to demonstrate use of built-in


packages (e.g. NumPy, Pandas).
# Write Python program to demonstrate use of built-in packages
(e.g. NumPy, Pandas).
import numpy

arr1 = numpy.array([1, 1, 2,3, 3, 4,4, 5, 5,6, 6, 7, 7, 8, 8])

print(f"arr1 = {arr1}")
print(f"Minimun Value In The arr1 = {arr1.min()}")
print(f"Maximun Value In The arr1 = {arr1.max()}")
print(f"Unique Values In The arr1 = {numpy.unique(arr1)}")
print(f"Sum Of The arr1 = {arr1.sum()}")
print(f"Mean Of The arr1 = {arr1.mean()}")
print(f"Median Of The arr1 = {numpy.median(arr1)}")
print(f"arr1 In The Form 3X5 Matrices")
print(arr1.reshape(3, 5))

Output:
PS F:\Python\Practicals\13> python px1.py
arr1 = [1 1 2 3 3 4 4 5 5 6 6 7 7 8 8]
Minimun Value In The arr1 = 1
Maximun Value In The arr1 = 8
Unique Values In The arr1 = [1 2 3 4 5 6 7 8]
Sum Of The arr1 = 70
Mean Of The arr1 = 4.666666666666667
Median Of The arr1 = 5.0
arr1 In The Form 3X5 Matrices
[[1 1 2 3 3]
[4 4 5 5 6]
[6 7 7 8 8]]

Px2: Write Python program to demonstrate use of user


defined packages.
# Write Python program to demonstrate use of user defined packages.
import GPT

gpt1 = GPT.GPT3_5()
gpt1.printModel()
gpt2 = GPT.GPT4o()
gpt2.printModel()
Practical No 13
gpt3 = GPT.GPTo1()
gpt3.printModel()

Output:
PS F:\Python\Practicals\13> python px2.py
I Am GPT3.5 Model
I Am Most Fast GPT Model

I Am GPT 4o Model
I Am Also Reasonable And Quick Also

I Am GPT o1 Model
I Am The Most Reasonable GPT Model

GPT/GPT1.py
class GPTo1:
def __init__(self):
print("I Am GPT o1 Model")
def printModel(self):
print("I Am The Most Reasonable GPT Model\n")

GPT/GPT2.py
class GPT3_5:
def __init__(self):
print("I Am GPT3.5 Model")
def printModel(self):
print("I Am Most Fast GPT Model\n")

GPT/GPT3.py
class GPT4o:
def __init__(self):
print("I Am GPT 4o Model")
def printModel(self):
print("I Am Also Reasonable And Quick Also\n")

GPT/__Init__.py
Practical No 13
from GPT.GPT2 import GPT3_5;
from GPT.GPT3 import GPT4o;
from GPT.GPT1 import GPTo1;

Ex1: Write a Python program to create two matrices and


perform addition, subtraction,multiplication and division
operation on matrix.
# Write a Python program to create two matrices and perform
addition, subtraction,multiplication and division operation on
matrix.

import numpy as np
mat1 = np.matrix([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
])
mat2 = np.matrix([
[4, 5, 6],
[7, 8, 9],
[1, 2, 3],
])
print(f"Mat1 = {mat1}")
print(f"Mat2 = {mat2}")

print("Mat1 + Mat2")
print(mat1 + mat2)

print("Mat1 - Mat2")
print(mat1 - mat2)

print("Mat1 / Mat2")
print(mat1 / mat2)

print("Mat1 * Mat2")
print(mat1 * mat2)

Output:
PS F:\Python\Practicals\13> python ex1.py
Mat1 = [[1 2 3]
[4 5 6]
[7 8 9]]
Mat2 = [[4 5 6]
[7 8 9]
Practical No 13
[1 2 3]]
Mat1 + Mat2
[[ 5 7 9]
[11 13 15]
[ 8 10 12]]
Mat1 - Mat2
[[-3 -3 -3]
[-3 -3 -3]
[ 6 6 6]]
Mat1 / Mat2
[[0.25 0.4 0.5 ]
[0.57142857 0.625 0.66666667]
[7. 4. 3. ]]
Mat1 * Mat2
[[ 21 27 33]
[ 57 72 87]
[ 93 117 141]]

Ex2: Write a Python program to concatenate two strings.


# Write a Python program to concatenate two strings.
import numpy

str1 = input("Enter String 1 : ")


str2 = input("Enter String 2 : ")

str3 = numpy.strings.add(str1,str2)
print(f"After Concatenating String str3 = {str3}")

Output:
PS F:\Python\Practicals\13> python ex2.py
Enter String 1 : Nikhil
Enter String 2 : Wankhede
After Concatenating String str3 = NikhilWankhede

Ex3: Write a NumPy program to generate six random


integers between 10 and 30.
# Write a NumPy program to generate six random integers between 10
and 30.

import numpy
Practical No 13

rand_int = numpy.random.randint(10,30,size=6)
print(f"6 Random Integers Between 10 and 30 Is {rand_int}")

Output:
PS F:\Python\Practicals\13> python ex3.py
6 Random Integers Between 10 and 30 Is [24 28 24 13 20 18]

You might also like