From 567efaaa42987ed8a40344ceb911f7ff57c4ecfd Mon Sep 17 00:00:00 2001 From: bt3gl <138340846+bt3gl-cryptographer@users.noreply.github.com> Date: Tue, 8 Aug 2023 17:26:50 -0700 Subject: [PATCH] Update README.md --- arrays_and_strings/README.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/arrays_and_strings/README.md b/arrays_and_strings/README.md index 25daa0d..12f9c32 100644 --- a/arrays_and_strings/README.md +++ b/arrays_and_strings/README.md @@ -62,10 +62,37 @@ def merge_overlapping_intervals(a, b):
+* a matrix is a 2d array. they can be used to represetn graphs where each node is a cell on the matrix which has 4 neighbors (except those cells on the edge and corners). + * in some languages (like C++), 2d arrays are represented as 1d, so an array of `m * n` elements represents `array[i][j]` as `array[i * n + j]`. -* dynamic 2d arrays a nested dynamic array. +* creating an empty matrix: +
+ +```python +zero_matrix = [ [0 for _ in range(len(matrix[0]))] for _ in range(len(matrix)) ] +``` + +
+ +* copying a matrix: + +
+ +```python +copied_matrix = [ row[:] for row in mattrix ] +``` + +
+ +* the transpose of a matrix can be found by interchanging its rows into columns or columns into rows: + +
+ +```python +transposed = zip(*matrix) +```