简体   繁体   中英

How to take a string of data from a 2D array python (2.7)

I'm sure this has been repeated since the dawn of time, but would anyone know how to access a string of data from a block as explained in better detail below:

array =

0,1,0,1,1,0

0,0,1,0,0,1

1,0,1,0,1,0

1,1,1,0,0,1

Want to access third row from element 2 to 6 to produce 0,1,0,0,1

Want to access fourth row from element 6 to 2 to produce 1,0,0,1,1

I have attempted to access data using this method:

Desired_info = Array(thrid_row, range(2, final_element)
Desired_info2 = Array(fourth_row, range(final_element, 2)

and my compiler crashes, I'm not sure if that's the right method but this is maddening and some assistance would be well appreciated.

array=[[0,1,0,1,1,0],[0,0,1,0,0,1],[1,0,1,0,1,0],[1,1,1,0,0,1]]

array

[[0, 1, 0, 1, 1, 0], [0, 0, 1, 0, 0, 1], [1, 0, 1, 0, 1, 0], [1, 1, 1, 0, 0, 1]]

array[2][1:]

[0, 1, 0, 1, 0]

array[3][:0:-1]

[1, 0, 0, 1, 1]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM