简体   繁体   中英

How to mask numpy 2D array by index?

I have a numpy 2D array with a range of 800. Now I only want to use the elements from index range 600 to 700 and set all other values to np.nan. The Index of the lasting elements should be the same as before. The length of the array should be the same too. Thanks!

import numpy as np
a = np.random.random ([800,4])

a[:600, :], a[700:, :] = np.nan, np.nan

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM