Ich habe dieses Arrays:Extract Array von Arrays von 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
Ich möchte das zweite Array in jedem Array extrahieren, und das Ergebnis ist wie folgt sein:
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.]]
Ich möchte die res
in einer Zeile Code bekommen, habe ich versucht, dies aber nicht
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]])
Kann mir jemand erklären, warum? Die einzige Lösung, die ich gefunden habe, ist, jeden Index explizit anzugeben (arr[0][1]...
), was ich nicht mochte.
'res = [x [1] für x in arr] '? – depperm