Is the behavior of numpy.in1d ​​changed when passing a set?

I get different behavior from in1ddepending on which machine I run my script on. On my desktop (numpy version 1.6.2) I'm trying

x = np.array('a b c d e f g h i j'.split()) 
np.in1d(x, set(['f', 'e', 'r']))
array([False, False, False, False,  True,  True, False, False, False, False], dtype=bool)

as I expected. On my laptop (version 1.8.1), the result is all FalseI don't want.

Playing a bit, I found that

np.in1d(x, ['f', 'e', 'r'])

works in both versions, but I don’t understand why the function does not work properly when transferring a set.

+4
source share
1 answer

I don't know when / if a change was made, but that is because the second argument np.in1dshould be similar to an array. Sets are not like arrays because they are not ordered.

() , . 1- , , 0-d.

a = np.array(set([1, 3, 5, 6]))

print(repr(a))
# array({1, 3, 5, 6}, dtype=object)

print(a.shape)
# ()

, - , , . , np.in1d ( ) , numpy.

issue github.

+8

All Articles