python - Indexing a numpy array with another array containing out of bounds values -


given following data array:

d=np.array([10,11,12,13,14])  

and indexing array:

i=np.array([0, 2, 3, 6]) 

what way of indexing d i (d[i]) instead of index out of bounds error 6, get:

np.array([10, 12, 13]) 

maybe use i[i < d.size]] elements less length of d:

print(d[i[i < d.size]]) [10 12 13] 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -