How to skim through 2d arrays efficiently

Is there any way to skim through the rows and columns of a 2d array efficiently?(
(Pyth 3.6)

What do you mean by skim? If you’re talking about traversal. Then use two nested for loops…

Is there a way to traverse the columns efficiently without using a forloop?

No matter what! To completely traverse a grid of dimensions n x m. You’ll take O(n x m)

1 Like

Thanks.

1 Like

I do it by making list of column…
ex…first column
col0 = [row[0] for row in mat]

Without prior information about the matrix, It is not possible to traverse and find our required information in less than O(nm) time.
Well if you have some information like it is skew matrix or Transpose is similar to original matrix , or maybe some equation that satisfies like a[i][j] + a[j][i] = value
then you might be able to cut the time taken in half by just avoiding iterating through all values for i (1<=i<=N) and j (1<=j<=M) .