0% found this document useful (0 votes)
15 views3 pages

Python Assignment_20230916_170922_0000

The document contains a Python assignment with four questions. Q1 requires filtering a list to remove duplicates while preserving order, Q2 involves expanding a list based on another list's values, Q3 focuses on matrix operations including averaging rows and replacing elements based on their mean, and Q4 involves applying a sliding window to find maximum values in a matrix. Each question provides specific input and expected output for clarity.

Uploaded by

shivaom1907
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)
15 views3 pages

Python Assignment_20230916_170922_0000

The document contains a Python assignment with four questions. Q1 requires filtering a list to remove duplicates while preserving order, Q2 involves expanding a list based on another list's values, Q3 focuses on matrix operations including averaging rows and replacing elements based on their mean, and Q4 involves applying a sliding window to find maximum values in a matrix. Each question provides specific input and expected output for clarity.

Uploaded by

shivaom1907
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/ 3

Python ASSIGNMENT

Q1.
Input
A = [3,3,3,4,4,5,5,7,7,8,8,8,3,3,1,1,1,4,4,4,6,9]

Write a logic to obtain output B as mentioned below


Output
B = [3,4,5,7,8,3,1,4,6,9]

Q2.
Input
A = [12,56,43,82]
B = [2,1,3,2]

Write a logic to obtain the output B mentioned below


Output
C = [12,12,56,43,43,43,82,82]

Q3: From the matrix of 10x10 as mentioned


A = [[49, 72, 28, 31, 10, 76, 45, 58, 22, 17],
[97, 47, 41, 63, 48, 65, 35, 23, 94, 90],
[47, 30, 79, 39, 13, 16, 1, 20, 49, 44],
[89, 78, 88, 36, 89, 15, 27, 30, 44, 83],
[ 6, 66, 47, 33, 46, 14, 16, 72, 4, 65],
[92, 32, 98, 98, 53, 6, 39, 74, 21, 46],
[47, 83, 86, 56, 98, 73, 46, 54, 82, 6],
[88, 91, 30, 16, 38, 5, 67, 48, 93, 69],
[86, 43, 32, 17, 96, 2, 38, 42, 61, 3],
[86, 88, 22, 14, 27, 80, 65, 93, 47, 25]]
Python ASSIGNMENT
Ist part:
Take the average of each row separately, and save it in B
B = [b0,b1,b2,b3,b4,b5,b6,b7,b8,b9]

[[49, 72, 28, 31, 10, 76, 45, 58, 22, 17],
[97, 47, 41, 63, 48, 65, 35, 23, 94, 90],
[47, 30, 79, 39, 13, 16, 1, 20, 49, 44],
[89, 78, 88, 36, 89, 15, 27, 30, 44, 83],
[ 6, 66, 47, 33, 46, 14, 16, 72, 4, 65],
[92, 32, 98, 98, 53, 6, 39, 74, 21, 46],
[47, 83, 86, 56, 98, 73, 46, 54, 82, 6],
[88, 91, 30, 16, 38, 5, 67, 48, 93, 69],
[86, 43, 32, 17, 96, 2, 38, 42, 61, 3],
[86, 88, 22, 14, 27, 80, 65, 93, 47, 25]]

IInd part:

Now, Check each element with its respective mean, i.e. First row elements
will be compared with b0 and second-row components will be compared
with b1, and so on.

If the element is greater than the mean value, then replace the element with 0
else leave it as it is.
Display the old matrix and the updated matrix.

IIIrd part:

Count the number of zeros and non-zero elements in the matrix and check if
the sum of both is equal to the total number of elements.
Python ASSIGNMENT
Q4:

A = [[49, 72, 28, 31, 10, 76, 45, 58, 22, 17],
[97, 47, 41, 63, 48, 65, 35, 23, 94, 90],
[47, 30, 79, 39, 13, 16, 1, 20, 49, 44],
[89, 78, 88, 36, 89, 15, 27, 30, 44, 83],
[ 6, 66, 47, 33, 46, 14, 16, 72, 4, 65],
[92, 32, 98, 98, 53, 6, 39, 74, 21, 46],
[47, 83, 86, 56, 98, 73, 46, 54, 82, 6],
[88, 91, 30, 16, 38, 5, 67, 48, 93, 69],
[86, 43, 32, 17, 96, 2, 38, 42, 61, 3],
[86, 88, 22, 14, 27, 80, 65, 93, 47, 25]]

Output
B = [[97,63,76,58,94],
[89,88,89,30,83],
[92,98,53,74,65],
[91,86,98,67,93],
[88,32,96,93,61]]

consider a 10x10 matrix with random values as above, it is not mandatory


to have the same values, it can be randomly generated values.

Now, you have to run a window of 2x2 over the 10x10 matrix and select
the maximum number out of each window and save it in a new matrix
which will have a size exactly equal to half of the previous original matrix.

You might also like