![]() |
VOOZH | about |
In Python, a Multi-dimensional List is a list containing other lists, often used to represent structured data like matrices, tables or 2D arrays. It’s useful for storing and accessing data in rows and columns, commonly applied in data analysis, mathematics and image processing.
For Example:
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
A multidimensional list is created by nesting lists within a single list. It allows data to be organized in rows and columns, similar to a matrix or table.
[[2, 4, 6, 8, 10], [3, 6, 9, 12, 15], [4, 8, 12, 16, 20]]
A zero matrix is a 2D list with all elements set to zero. It’s commonly used as an initial structure for mathematical operations, data storage or placeholders before inserting actual values.
[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
Explanation:
This approach retrieves each row from the outer list directly. It’s useful when you want to process or print entire rows one at a time without worrying about column indices.
[2, 4, 6, 8, 10] [3, 6, 9, 12, 15] [4, 8, 12, 16, 20]
This method accesses each element using row and column indices. It provides complete control when working with individual elements.
2 4 6 8 1 3 5 7 8 6 4 2 7 5 3 1
Explanation:
Adds a new sublist (row) to the end of the outer list. Commonly used when dynamically building matrices or adding data rows.
[[2, 4, 6], [3, 6, 9], [5, 10, 15]]
Extends a chosen sublist by adding multiple elements from another iterable. Useful for appending more data to an existing row.
[[2, 4, 6, 8, 10], [3, 6, 9]]
Reverses the order of elements within a list. It can be applied either to a specific sublist or to the entire outer list.
[[2, 4, 6], [9, 6, 3]] [[9, 6, 3], [2, 4, 6]]
You can directly access or modify elements in a specific position using double indexing syntax a[i][j].
2 [[1, 2], [9, 4]]
List comprehensions provide a compact way to modify or filter elements in rows or columns, ideal for data transformations like scaling or filtering.
[[2, 4, 6], [8, 10, 12]]