Jul-26-2020, 12:02 AM
Jul-26-2020, 03:10 AM
Use
-1
index to get the last element in row/column, e.g.>>> import numpy as np >>> x=np.random.rand(10, 10) >>> [x[0, 0], x[-1, 0], x[0, -1], x[-1, -1]]
Jul-26-2020, 03:13 AM
You can ask for the corner values one at a time just by indexing into the array. And just like regular python lists, you can use the -1 index for the last value. So the corner values are [0,0], [0,-1], [-1,0], and [-1,-1], for any 2D array.
>>> niner = np.array(range(81)).reshape(9,9) >>> print(niner[-1,0]) 72Or to combine them into a new array with advanced indexing, we can give all the rows we want and all the columns we want:
>>> print(niner[[0,0,-1,-1],[0,-1,0,-1]]) [ 0 8 72 80]
Jul-26-2020, 07:32 AM
Thanks for this,
much appreciated
much appreciated