numpy - python ndarray perform A[:, ... , l, .. :] at specific index -


this question has answer here:

suppose have np.ndarray a of variable known shape. perform operation a[:, ... , :, l , :, ... : ] l known integer occurs @ known index i in [...].

there rather easy solution have searched internet , couldn't find anything.

you can add arbitary number of dimensions in []:

[(slice(none), ) * + (l, )] 

this equivalent of i :, , l. example:

i = 2 l = 3 a[(slice(none), ) * + (l, )] 

would equivalent to:

a[:, :, 3] 

Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -