简体   繁体   中英

How to combine two arrays

I want to combine 2 arrays to get an array composed of the common values in the arrays. For example:

x = np.array ([1,2,3,4,6,11])

y = np.array ([3,6,5,2,9,8])

The result should be z = [2, 3, 6] which are the values that are common to both.

You're looking for the function np.intersect1d(x,y) .

Edit: also, keep this readily accessible: https://docs.scipy.org/doc/numpy-1.17.0/numpy-ref-1.17.0.pdf I can't tell you how much I just pop over to it regularly for those kinds of weird one-off functions.

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