I have this arrays:
arr = np.array([[[ -1., -1., -1., 0., 0., 0.],
[ 0.1, 0.1, 0.1, 2., 3., 4.]], # <-- this one
[[ -1., -1., -1., 0., 0., -1.],
[ 0.1, 0.1, 0.1, 16., 17., 0.1]], # <-- and this one
[[ -1., -1., -1., 0., 0., 0.],
[ 0.1, 0.1, 0.1, 4., 5., 6.]], # <-- and this one
[[ 0., 0., 0., -1., 0., 0.],
[ 1., 2., 3., 0.1, 1., 2.]], # <-- and this one
[[ -1., -1., 0., 0., 0., 0.],
[ 0.1, 0.1, 1., 9., 10., 11.]]]) # <-- and the last one
I want to extract the 2nd array in each array, and the result should be as follows:
res = [[ 0.1, 0.1, 0.1, 2., 3., 4.],
[ 0.1, 0.1, 0.1, 16., 17., 0.1],
[ 0.1, 0.1, 0.1, 4., 5., 6.],
[ 1., 2., 3., 0.1, 1., 2.],
[ 0.1, 0.1, 1., 9., 10., 11.]]
I want to get the res in one line of code, I tried this but it didn't work
arr[:][1] # select the element 1 in each array
# I got
array([[ -1. , -1. , -1. , 0. , 0. , -1. ],
[ 0.1, 0.1, 0.1, 16. , 17. , 0.1]])
Can anyone explain why?
The only solution that I found is to explicitly indicate each index (arr[0][1]...), which I didn't like.
res = [x[1] for x in arr]?