numpy.not_equal#
- numpy.not_equal(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature]) = <ufunc 'not_equal'>#
逐元素返回 (x1 != x2)。
- 参数:
- x1, x2array_like
Input arrays. If
x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output)。- outndarray, None, or tuple of ndarray and None, optional
结果存储的位置。如果提供了,它必须具有输入广播到的形状。如果未提供或为 None,则返回一个新分配的数组。元组(仅可能作为关键字参数)的长度必须等于输出的数量。
- wherearray_like, optional
此条件将广播到输入。在条件为 True 的位置,out 数组将设置为 ufunc 结果。在其他地方,out 数组将保留其原始值。请注意,如果通过默认的
out=None创建了一个未初始化的 out 数组,那么其中条件为 False 的位置将保持未初始化状态。- **kwargs
有关其他关键字参数,请参阅 ufunc 文档。
- 返回:
- outndarray 或标量
输出数组,对 x1 和 x2 进行逐元素比较。通常为 bool 类型,除非传递了
dtype=object。如果 x1 和 x2 都是标量,则此函数返回一个标量。
另请参阅
示例
>>> import numpy as np >>> np.not_equal([1.,2.], [1., 3.]) array([False, True]) >>> np.not_equal([1, 2], [[1, 3],[1, 4]]) array([[False, True], [False, True]])
在 ndarrays 上,可以使用
!=运算符作为np.not_equal的简写。>>> a = np.array([1., 2.]) >>> b = np.array([1., 3.]) >>> a != b array([False, True])