Say i have:
H = [array(a), array(b), array(c)...]
a = [[1,2,3,4,5,6],
[11,22,33,44,55,66], #row 1 of H[0]
[111,222,333,444,555,666]]
b = [[7,8,9,0,1,2],
[77,88,99,00,11,22],
[777,888,999,000,111,222]]
c = ...
I want to access row 1 of H[0], but then move onto accessing the rows within H[1] and so on.
My question(s):
1) How do i call on row 1 of H[0]?
2) How do i then, after going through all rows in H[0], make a loop run to H[1]?
I know i need something like
for i in range(len(H)):
do stuff to rows until the last row in H[i]
move onto H[i+1]
do same stuff
stop when (criteria here reached)
All help is appreciated. Thank you.
Edit: I now know I can access this by H[0][1]
but i actually need the 0th column values within each row of the arrays. So, i need 11
from H[0][1]
. How do i do this?
H = [a, b, c]
Right? If so, then answers:
1)
H[0][1] # 0 - "a" array; 1 - row with index 1 in "a"
2)
for arr in H: # for array in H: a,b,c,...
for row in arr: # for row in current array
# do stuff here
Upd:
One more example shows iterating through arrays, their's rows and elements:
a = [[1, 2],
[3, 4]]
b = [[5, 6],
[7, 8]]
H = [a, b]
for arr_i, arr in enumerate(H):
print('array {}'.format(arr_i))
for row_i, row in enumerate(arr):
print('\trow {}'.format(row_i))
for el in row:
print('\t{}'.format(el))
Output:
array 0
row 0
1
2
row 1
3
4
array 1
row 0
5
6
row 1
7
8
What about:
for array in H:
for row in array:
# do stuff
This loop automatically moves on to the next array when the current array is finished.
If you need indices for the arrays then something like:
for array in H:
for i, row in enumerate(array):
for j, value in enumerate(row):
# do stuff
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With