
我发现源
ndarray.__contains__中
numpy/core/src/multiarray/sequence.c。作为消息来源的评论,
thing in x
相当于
(x == thing).any()
用于ndarray
x,无论尺寸
x和
thing。仅当
thing是标量时才有意义;广播的结果
thing不是标量时,会导致我观察到怪异的结果,以及
array([1,2, 3]) in array(1)我没想尝试的奇怪之处。确切的来源是
static intarray_contains(PyArrayObject *self, PyObject *el){ int ret; PyObject *res, *any; res = PyArray_EnsureAnyArray(PyObject_RichCompare((PyObject *)self, el, Py_EQ)); if (res == NULL) { return -1; } any = PyArray_Any((PyArrayObject *)res, NPY_MAXDIMS, NULL); Py_DECREF(res); ret = PyObject_IsTrue(any); Py_DECREF(any); return ret;}欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)