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

Tutorial 7

Uploaded by

omkar90117350
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)
1 views4 pages

Tutorial 7

Uploaded by

omkar90117350
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

Tutorial 7

Name:Omkar Gaikwad
Class:CE2
Batch:A
PRN:B25CE1083

Problem Statement :Design and implement a python program by using numpy


library to perform basic arithmetic operations on 2d array of the same size the
program should display original array and the result of each operation

Code

import numpy as np

# Creating 2D arrays using numpy


array1 = [Link]([[4, 5, 6], [7, 8, 9]])
array2 = [Link]([[5, 6, 7], [10, 11, 12]])

print("First Array:\n", array1)


print("Second Array:\n", array2)

# Addition
addition = array1 + array2
print("\nAddition of arrays:\n", addition)

# Subtraction
subtraction = array1 - array2
print("\nSubtraction of arrays:\n", subtraction)

# Multiplication
multiplication = array1 * array2
print("\nElement-wise multiplication of arrays:\n", multiplication)

# Division
division = array1 / array2
print("\nElement-wise division of arrays:\n", division)

Output:
Alternate method without using numpy
Using For Loop

# 2D arrays using lists


array1 = [[4,5,6],[7,8,9]]
array2 = [[5,6,7],[10,11,12]]

print("First Array:", array1)


print("Second Array:", array2)

# Addition
print("\nAddition:")
for i in range(2):
for j in range(3):
print(array1[i][j] + array2[i][j], end=" ")
print()

# Subtraction
print("\nSubtraction:")
for i in range(2):
for j in range(3):
print(array1[i][j] - array2[i][j], end=" ")
print()

# Multiplication
print("\nMultiplication:")
for i in range(2):
for j in range(3):
print(array1[i][j] * array2[i][j], end=" ")
print()

# Division
print("\nDivision:")
for i in range(2):
for j in range(3):
print(array1[i][j] / array2[i][j], end=" ")
print()

Output:

You might also like