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

(Pyth 3.6)

# How to skim through 2d arrays efficiently

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)

Thanks.

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) .