- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Conversion to N*N tuple matrix in Python
When it is required to convert an N*N tuple into a matrix, a simple loop and the * operator can be used.
The * operator can be used to get the product of two values. It can also be used to multiple a single value multiple times and display it on the console.
Below is a demonstration of the same −
my_tuple_1 = ((11, 14), (0, 78), (33, 11), (10, 78)) print("The tuple of tuple is : ") print(my_tuple_1) N = 4 print("The value of N has been initialized to "+ str(N)) my_result =  for tup in my_tuple_1 : my_result.append( tup +(0, ) * (N - len(tup))) print("The tuple after filling in the values is: ") print(my_result)
The tuple of tuple is : ((11, 14), (0, 78), (33, 11), (10, 78)) The value of N has been initialized to 4 The tuple after filling in the values is: [(11, 14, 0, 0), (0, 78, 0, 0), (33, 11, 0, 0), (10, 78, 0, 0)]
- A nested tuple is defined and is displayed on the console.
- The value of 'N' is defined, and displayed.
- Another empty list is created.
- The nested tuple is iterated, and 0 is added after every value, and repeated 'N- len(tuple)' times.
- This is assigned to a value.
- It is displayed on the console.
- Matrix creation of n*n in Python
- Conversion of Array To ArrayList in Java\n\n
- Decimal to Binary conversion\n
- Dictionary to list of tuple conversion in Python
- Split tuple into groups of n in Python
- Conversion of Set To Stream in Java\n
- Conversion of Stream To Set in Java\n
- Conversion of Binary to Gray Code\n
- Conversion of Gray Code to Binary\n
- Raise a square matrix to the power n in Linear Algebra in Python
- Print Matrix in spiral way\n
- How to match nonword characters in Python using Regular Expression?\n\n\n\n
- How to print a matrix of size n*n in spiral order using C#?
- Remove similar element rows in tuple Matrix in Python
- How to rotate a matrix of size n*n to 90 degree using C#?