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

Experiment No 11

The document outlines Experiment No 11, demonstrating the use of NumPy for various array operations such as addition, subtraction, multiplication, division, exponentiation, and modulus. It also covers statistical functions like mean, median, minimum, and maximum, as well as trigonometric functions. Each operation is illustrated with Python code examples and expected outputs.

Uploaded by

dakshmahajan2022
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)
12 views4 pages

Experiment No 11

The document outlines Experiment No 11, demonstrating the use of NumPy for various array operations such as addition, subtraction, multiplication, division, exponentiation, and modulus. It also covers statistical functions like mean, median, minimum, and maximum, as well as trigonometric functions. Each operation is illustrated with Python code examples and expected outputs.

Uploaded by

dakshmahajan2022
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/ 4

Experiment No 11

Name: Mehal Anil Naxine

Roll No: 54

Batch: B3

Date: 25/03/25

Aim: Program to demonstrate use of NumPy: Array objects.


Program:-
#NumPy Array Element-Wise Addition/ Subtraction/ Multiplication/ Division/
Exponentiation:

Addition:
import numpy as np
first_array = np.array([1, 3, 5, 7])
second_array = np.array([2, 4, 6, 8])
# using the + operator
result1 = first_array + second_array
print("Using the + operator:",result1)
# using the add() function
result2 = np.add(first_array, second_array)
print("Using the add() function:",result2)
Output:-

Subtraction:
import numpy as np
first_array = np.array([3, 9, 27, 81])
second_array = np.array([2, 4, 8, 16])
# using the - operator
result1 = first_array - second_array
print("Using the - operator:",result1)
# using the subtract() function
result2 = np.subtract(first_array, second_array)
print("Using the subtract() function:",result2)

Output:-
Multiplication:
import numpy as np
first_array = np.array([1, 3, 5, 7])
second_array = np.array([2, 4, 6, 8])
# using the * operator
result1 = first_array * second_array
print("Using the * operator:",result1)
# using the multiply() function
result2 = np.multiply(first_array, second_array)
print("Using the multiply() function:",result2)

Output:-

Division:
import numpy as np
first_array = np.array([1, 2, 3])
second_array = np.array([4, 5, 6])
# using the / operator
result1 = first_array / second_array
print("Using the / operator:",result1)
# using the divide() function
result2 = np.divide(first_array, second_array)
print("Using the divide() function:",result2)
Output:-

Power:
import numpy as np
array1 = np.array([1, 2, 3])
# using the ** operator
result1 = array1 ** 2
print("Using the ** operator:",result1)
# using the power() function
result2 = np.power(array1, 2)
print("Using the power() function:",result2)
Output:-
Mod:
import numpy as np
first_array = np.array([9, 10, 20])
second_array = np.array([2, 5, 7])
# using the % operator
result1 = first_array % second_array
print("Using the % operator:",result1)
# using the mod() function
result2 = np.mod(first_array, second_array)
print("Using the mod() function:",result2)
Output:-

NumPy Array Statistical Functions:


import numpy as np
# create a numpy array
marks = np.array([76, 78, 81, 66, 85])
# compute the mean of marks
mean_marks = np.mean(marks)
print("Mean:",mean_marks)
# compute the median of marks
median_marks = np.median(marks)
print("Median:",median_marks)
# find the minimum and maximum marks
min_marks = np.min(marks)
print("Minimum marks:", min_marks)
max_marks = np.max(marks)
print("Maximum marks:", max_marks)

Output:-

NumPy Trigonometric Functions:


import numpy as np # import numpy package
sin_90 = np.sin(90) # sine value of degree 90 in degree
print("Sine value of angle 90 in degree = ",sin_90) # print sine value
cos_180 = np.cos(180) # cosine value of degree 180 in degree
print("Cosine value of angle 180 in degree = ", cos_180) # print cosine value
tan_60 = np.tan(60) # tangent value of degree 60 in degree
print("Tangent value of angle 60 in degree = ", tan_60) # print tangent value

Output:-

You might also like