I want to extract certain columns out of a 3d numpy array. Imagine a 3d numpy array like
[[[ 65 234 169]
[203 191 245]
[ 36 58 196]
[207 208 143]
[251 208 187]]
[[ 79 69 237]
[ 13 124 42]
[104 165 82]
[170 178 178]
[ 66 42 210]]
[[ 40 163 219]
[142 37 140]
[ 75 205 143]
[246 30 221]
[ 16 98 102]]]
If - for example - columns 2-4 should be extracted, I want to get a resulting 3d array like
[[[203 191 245]
[ 36 58 196]
[207 208 143]]
[[ 13 124 42]
[104 165 82]
[170 178 178]]
[[142 37 140]
[ 75 205 143]
[246 30 221]]]
I've been playing around with array indexing and slicing for a few hours, but I don't get it working. Could anyboday help me or?
Thanks in advance and best regards.
In [12]: array
Out[12]:
array([[[ 65, 234, 169],
[203, 191, 245],
[ 36, 58, 196],
[207, 208, 143],
[251, 208, 187]],
[[ 79, 69, 237],
[ 13, 124, 42],
[104, 165, 82],
[170, 178, 178],
[ 66, 42, 210]],
[[ 40, 163, 219],
[142, 37, 140],
[ 75, 205, 143],
[246, 30, 221],
[ 16, 98, 102]]])
In [13]: array[:, 1:4, :]
Out[13]:
array([[[203, 191, 245],
[ 36, 58, 196],
[207, 208, 143]],
[[ 13, 124, 42],
[104, 165, 82],
[170, 178, 178]],
[[142, 37, 140],
[ 75, 205, 143],
[246, 30, 221]]])
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.