CANN AsNumpy逻辑函数API
Logic Functions【免费下载链接】asnumpy-docs项目地址: https://gitcode.com/cann/asnumpy-docs::: info This API section currently keeps a curated subset of representative APIs. Additional API documentation is temporarily hidden while the AsNumpy frontend and documentation system are still undergoing major restructuring, and it will be expanded after the frontend stabilizes. This document is for reference only. :::Truth Value Testingasnumpy.allasnumpy.all(x: ArrayLike, axis: AxisLike None, keepdims: bool False) - ndarrayCheck whether all elements evaluate to True.Argumentsx(ArrayLike): The input array to be checked.axis(AxisLike, optional): The axis or axes along which to perform the logical AND reduction.keepdims(bool, optional): If True, reduced axes are retained in the result.Returnsndarray: A boolean array or scalar indicating whether all elements evaluate to True.See Alsonumpy.allasnumpy.anyExamples import asnumpy as ap import numpy as np a ap.ndarray.from_numpy(np.array([True, True, True])) ap.all(a) b ap.ndarray.from_numpy(np.array([True, False, True])) ap.all(b)asnumpy.anyasnumpy.any(x: ArrayLike, axis: AxisLike None, keepdims: bool False) - ndarrayCheck whether any element evaluates to True.Argumentsx(ArrayLike): The input array to be checked.axis(AxisLike, optional): The axis or axes along which to perform the logical OR reduction.keepdims(bool, optional): If True, reduced axes are retained in the result.Returnsndarray: A boolean array or scalar indicating whether any element evaluates to True.See Alsonumpy.anyasnumpy.allExamples import asnumpy as ap import numpy as np a ap.ndarray.from_numpy(np.array([False, False, True])) ap.any(a) b ap.ndarray.from_numpy(np.array([False, False, False])) ap.any(b)Logical Operationsasnumpy.logical_andasnumpy.logical_and(x1: ArrayLike, x2: ArrayLike) - ndarrayApply boolean AND logic across corresponding elements of two arrays.Argumentsx1(ArrayLike): The first input array.x2(ArrayLike): The second input array.Returnsndarray: A boolean array containing the result of the logical AND.See Alsonumpy.logical_andExamples import asnumpy as ap ap.logical_and(True, False) array(False) ap.logical_and([True, False], [True, True]) array([ True, False])asnumpy.logical_orasnumpy.logical_or(x1: ArrayLike, x2: ArrayLike) - ndarrayApply boolean OR logic across corresponding elements of two arrays.Argumentsx1(ArrayLike): The first input array.x2(ArrayLike): The second input array.Returnsndarray: A boolean array containing the result of the logical OR.See Alsonumpy.logical_orExamples import asnumpy as ap ap.logical_or(True, False) array(True)asnumpy.logical_notasnumpy.logical_not(x: ArrayLike) - ndarrayInvert the boolean value of each array element.Argumentsx(ArrayLike): The input array.Returnsndarray: A boolean array containing the result of the logical NOT.See Alsonumpy.logical_notExamples import asnumpy as ap ap.logical_not(True) array(False) ap.logical_not([True, False]) array([False, True])asnumpy.logical_xorasnumpy.logical_xor(x1: ArrayLike, x2: ArrayLike) - ndarrayApply exclusive OR logic across corresponding elements of two arrays.Argumentsx1(ArrayLike): The first input array.x2(ArrayLike): The second input array.Returnsndarray: A boolean array containing the result of the logical XOR.See Alsonumpy.logical_xorExamples import asnumpy as ap ap.logical_xor(True, False) array(True)Comparisonasnumpy.greaterasnumpy.greater(x1: ArrayLike, x2: ArrayLike, dtype: DTypeLike None) - ndarrayDetermine whether elements of x1 are greater than those of x2.Argumentsx1(ArrayLike): First input.x2(ArrayLike): Second input.dtype(DTypeLike, optional): Desired data type for the output array.Returnsndarray: An array containing the result of the element-wise comparison.See Alsonumpy.greaterExamples import asnumpy as ap ap.greater([4, 2], [2, 2]) array([ True, False])asnumpy.greater_equalasnumpy.greater_equal(x1: ArrayLike, x2: ArrayLike, dtype: DTypeLike None) - ndarrayDetermine whether elements of x1 are greater than or equal to those of x2.Argumentsx1(ArrayLike): First input.x2(ArrayLike): Second input.dtype(DTypeLike, optional): Desired data type for the output array.Returnsndarray: An array containing the result of the element-wise comparison.See Alsonumpy.greater_equalExamples import asnumpy as ap import numpy as np ap.greater_equal(ap.ndarray.from_numpy(np.array([4, 2, 1], dtypenp.int32)), ap.ndarray.from_numpy(np.array([2, 2, 2], dtypenp.int32))) array([ True, True, False])asnumpy.lessasnumpy.less(x1: ArrayLike, x2: ArrayLike, dtype: DTypeLike None) - ndarrayDetermine whether elements of x1 are less than those of x2.Argumentsx1(ArrayLike): First input.x2(ArrayLike): Second input.dtype(DTypeLike, optional): Desired data type for the output array.Returnsndarray: An array containing the result of the element-wise comparison.See Alsonumpy.lessExamples import asnumpy as ap ap.less([1, 2, 3], [2, 2, 2]) array([ True, False, False])asnumpy.less_equalasnumpy.less_equal(x1: ArrayLike, x2: ArrayLike, dtype: DTypeLike None) - ndarrayDetermine whether elements of x1 are less than or equal to those of x2.Argumentsx1(ArrayLike): First input.x2(ArrayLike): Second input.dtype(DTypeLike, optional): Desired data type for the output array.Returnsndarray: An array containing the result of the element-wise comparison.See Alsonumpy.less_equalExamples import asnumpy as ap import numpy as np ap.less_equal(ap.ndarray.from_numpy(np.array([1, 2, 3], dtypenp.int32)), ap.ndarray.from_numpy(np.array([2, 2, 2], dtypenp.int32))) array([ True, True, False])asnumpy.equalasnumpy.equal(x1: ArrayLike, x2: ArrayLike, dtype: DTypeLike None) - ndarrayCompare two arrays for equality element by element.Argumentsx1(ArrayLike): First input.x2(ArrayLike): Second input.dtype(DTypeLike, optional): Desired data type for the output array.Returnsndarray: An array containing the result of the element-wise comparison.See Alsonumpy.equalExamples import asnumpy as ap ap.equal([1, 2, 3], [1, 4, 3]) array([ True, False, True])asnumpy.not_equalasnumpy.not_equal(x1: ArrayLike, x2: ArrayLike, dtype: DTypeLike None) - ndarrayCompare two arrays for inequality element by element.Argumentsx1(ArrayLike): First input.x2(ArrayLike): Second input.dtype(DTypeLike, optional): Desired data type for the output array.Returnsndarray: An array containing the result of the element-wise comparison.See Alsonumpy.not_equalExamples import asnumpy as ap ap.not_equal([1, 2, 3], [1, 4, 3]) array([False, True, False])Otherasnumpy.isfiniteasnumpy.isfinite(x: ArrayLike) - ndarrayIdentify which array elements are regular numbers (not infinity or NaN).Argumentsx(ArrayLike): The input array to be tested.Returnsndarray: A boolean array with the same shape asx.See Alsonumpy.isfiniteExamples import asnumpy as ap import numpy as np ap.isfinite([1, np.inf, np.nan]) array([ True, False, False])asnumpy.isinfasnumpy.isinf(x: ArrayLike) - ndarrayDetect infinite values (both positive and negative) in the input array.Argumentsx(ArrayLike): The input array to be tested.Returnsndarray: A boolean array indicating infinite values.See Alsonumpy.isinfExamples import asnumpy as ap import numpy as np ap.isinf(ap.ndarray.from_numpy(np.array([1, np.inf, -np.inf], dtypenp.float32))) array([False, True, True])asnumpy.isneginfasnumpy.isneginf(x: ArrayLike) - ndarrayIdentify occurrences of negative infinity within the array.Argumentsx(ArrayLike): The input array to be tested.Returnsndarray: A boolean array indicating negative infinity values.See Alsonumpy.isneginfExamples import asnumpy as ap import numpy as np ap.isneginf(ap.ndarray.from_numpy(np.array([1, -np.inf, np.inf], dtypenp.float32))) array([False, True, False])asnumpy.isposinfasnumpy.isposinf(x: ArrayLike) - ndarrayIdentify occurrences of positive infinity within the array.Argumentsx(ArrayLike): The input array to be tested.Returnsndarray: A boolean array indicating positive infinity values.See Alsonumpy.isposinfExamples import asnumpy as ap import numpy as np ap.isposinf(ap.ndarray.from_numpy(np.array([1, np.inf, -np.inf], dtypenp.float32))) array([False, True, False])【免费下载链接】asnumpy-docs项目地址: https://gitcode.com/cann/asnumpy-docs创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考