- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
Python program to find the redundancy rates for each row of a matrix
When it is required to find the redundancy rates for every row of a matrix, a simple iteration and the ‘append’ method can be used.
Below is a demonstration of the same
my_list = [[91, 52, 12, 29, 33], [54, 54, 54, 54, 54], [11, 22, 33, 59, 95]] print("The list is :") print(my_list) my_result =  for sub in my_list: my_result.append(1 - len(set(sub)) / len(sub)) print("The result is :") print(my_result)
The list is : [[91, 52, 12, 29, 33], [54, 54, 54, 54, 54], [11, 22, 33, 59, 95]] The result is : [0, 1, 0]
A list of list is defined and is displayed on the console.
An empty list is created.
The original list is iterated over, and when a condition is met, it is appended to the empty list.
This is displayed as the output on the console.
- Related Articles
- Program to find smallest intersecting element of each row in a matrix in Python
- C++ program to find the Sum of each Row and each Column of a Matrix
- How to find the row products for each row in an R matrix?
- Find the maximum element of each row in a matrix using Python
- How to find the row sum for each column by row name in an R matrix?
- Find the column index of least value for each row of an R matrix
- Python Program to Cyclic Redundancy Check
- How to find the row means for each matrix stored in an R list?
- Python Program to convert a list into matrix with size of each row increasing by a number
- Find maximum element of each row in a matrix in C++
- Find the column number with largest value for each row in an R matrix.
- Program to find valid matrix given row and column sums in Python
- Python Program to find the transpose of a matrix
- Program to find number of elements in matrix follows row column criteria in Python