Unique matrix program in python assignment expert

you are given an N*N matrix. Write a program to check if the matrix is unique or not. A unique matrix is a matrix if every row and column of the matrix contains all the integers from 1 to N.

INPUT:

4

1 2 3 4

2 3 4 1

3 4 1 2

4 1 2 3

OUTPUT- True.

INPUT:

4

1 2 3 3

2 3 4 1

3 4 1 2

4 1 2 3

OUTPUT- False

def calculate_unique[matr, size]:


	ells = [i+1 for i in range[size]]
	for i in range[size]:
		row = matr[i]
		col = [matr[j][i] for j in range[size]]
		for el in ells:
			if [el not in row] or [el not in col]:
				return False


	return True


n = int[input["n: "]]
while n < 0:


	n = int[input["n: "]]




M = []
for i in range[n]:
	row = [int[i] for i in input[f"{i+1} line\n"].split[]]
	while len[row] != n:
		row = [int[i] for i in input[f"{i+1} line\n"].split[]]
	M.append[row]


print[calculate_unique[M, n]]

Learn more about our help with Assignments: Python

Unique Matrix

You are given a N*N matrix. write a program to check if the matrix is unique or not. A unique Matrix is a matrix if every row and column of the matrix contains all the integers from 1 to N

Input:

The first line contains an integer N.

The next N lines contains N space separated values of the matrix.

Output:

The output contains a single line and should be True if the matrix is unique matrix and False otherwise.

Sample input:

4

1 2 3 4

2 3 4 1

3 4 1 2

4 1 2 3

Sample output:

True

def check_uniq[matrix, n]:
	all_int = set[range[1, n+1]]
	for i in range[n]:
		row = matrix[i]
		col = [matrix[j][i] for j in range[n]]
		if set[row] != all_int or set[col] != all_int:
			return False
		
	return True

n = int[input[]]
matrix = [[int[el] for el in input[].split[]] for _ in range[n]]
print[check_uniq[matrix, n]]

Learn more about our help with Assignments: Python

 Harry  August 23, 2022

Today, we will see how to replace elements with zeros in Python. We will write two programs for that, in the first one, we will see how to replace elements with zeros in a matrix created using lists in Python, and in the second one, we will use NumPy.

1. Replace Elements with Zeros in a matrix of List in Python

matrix = [[1, 2, 3],
          [4, 5, 6],
          [7, 8, 9]]

for i in range[len[matrix]]:
    for j in range[len[matrix]]:
        matrix[i][j] = 0
        
print[matrix]

Output:

2. Replace Elements with Zeros in a matrix of List in Python

import numpy as np

matrix = np.array[[[1, 2, 3],
          [4, 5, 6],
          [7, 8, 9]]]

for i in range[len[matrix]]:
    for j in range[len[matrix]]:
        matrix[i][j] = 0
        
print[matrix]

Output:

Also Read:

  • Ticket selling in Cricket Stadium using Python | Assignment Expert
  • Split the sentence in Python | Assignment Expert
  • String Slicing in JavaScript | Assignment Expert
  • First and Last Digits in Python | Assignment Expert
  • List Indexing in Python | Assignment Expert
  • Date Format in Python | Assignment Expert
  • New Year Countdown in Python | Assignment Expert
  • Add Two Polynomials in Python | Assignment Expert
  • Sum of even numbers in Python | Assignment Expert
  • Evens and Odds in Python | Assignment Expert
  • A Game of Letters in Python | Assignment Expert
  • Sum of non-primes in Python | Assignment Expert
  • Smallest Missing Number in Python | Assignment Expert
  • String Rotation in Python | Assignment Expert
  • Secret Message in Python | Assignment Expert
  • Word Mix in Python | Assignment Expert
  • Single Digit Number in Python | Assignment Expert
  • Shift Numbers in Python | Assignment Expert
  • Weekend in Python | Assignment Expert
  • Shift Numbers in Python | Assignment Expert
  • Temperature Conversion in Python | Assignment Expert
  • Special Characters in Python | Assignment Expert
  • Sum of Prime Numbers in the Input in Python | Assignment Expert
  • Numbers in String-1 in Python | Assignment Expert
  • Replace Elements with Zeros in Python | Assignment Expert
  • Remove Words in Python | Assignment Expert
  • Print Digit 9 in Python | Assignment Expert
  • First Prime Number in Python | Assignment Expert
  • Simple Calculator in Python | Assignment Expert
  • Average of Given Numbers in Python | Assignment Expert

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at Thank you

Post navigation

Categories

Our Services

Contact us on WhatsApp at +91-9760648231 for help with your-

python project
python assignment
python management assignment
python management project
python freelancer
assignment helper
machine learning expert
machine learning helper
ai ml helper
ai ml expert
ml freelancer
machine learning homework helper
final year project
project helper
assignment expert
project expert
programming expert
homework helper
homework expert

Chủ Đề