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

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

javascript - Confirm a form & display message if form is valid with JQuery -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -