简体   繁体   中英

How do I remove all elements from a numpy array that are equal to zero in another array?

How do I remove all elements from a numpy array that are equal to zero in another array?
I want to use the indices of one numpy array mask where mask==0 to delete the elements of another same-shaped array array .
I tried something like np.delete(array,mask==0) but that just gave me an error.

use np.where

array = array[np.where(another_array != 0)]

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