:mod:`heat.arithmetics` ============================ .. py:module:: heat.core.arithmetics .. autoapi-nested-parse:: Arithmetic functions for DNDarrays Module Contents --------------- .. function:: add(t1: Union[heat.core.dndarray.DNDarray, float], t2: Union[heat.core.dndarray.DNDarray, float], /, out: Optional[heat.core.dndarray.DNDarray] = None, *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> heat.core.dndarray.DNDarray Element-wise addition of values from two operands, commutative. Takes the first and second operand (scalar or :class:`~heat.core.dndarray.DNDarray`) whose elements are to be added as argument and returns a ``DNDarray`` containing the results of element-wise addition of ``t1`` and ``t2``. :param t1: The first operand involved in the addition :type t1: DNDarray or scalar :param t2: The second operand involved in the addition :type t2: DNDarray or scalar :param out: The output array. It must have a shape that the inputs broadcast to and matching split axis. If not provided, a freshly allocated array is returned. :type out: DNDarray, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out` array will be set to the added value. Elsewhere, the `out` array will retain its original value. If an uninitialized `out` array is created via the default `out=None`, locations within it where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out` array. :type where: DNDarray, optional .. rubric:: Examples >>> import heat as ht >>> ht.add(1.0, 4.0) DNDarray(5., dtype=ht.float32, device=cpu:0, split=None) >>> T1 = ht.float32([[1, 2], [3, 4]]) >>> T2 = ht.float32([[2, 2], [2, 2]]) >>> ht.add(T1, T2) DNDarray([[3., 4.], [5., 6.]], dtype=ht.float32, device=cpu:0, split=None) >>> s = 2.0 >>> ht.add(T1, s) DNDarray([[3., 4.], [5., 6.]], dtype=ht.float32, device=cpu:0, split=None) .. function:: bitwise_and(t1: Union[heat.core.dndarray.DNDarray, float], t2: Union[heat.core.dndarray.DNDarray, float], /, out: Optional[heat.core.dndarray.DNDarray] = None, *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> heat.core.dndarray.DNDarray Compute the bitwise AND of two :class:`~heat.core.dndarray.DNDarray` ``t1`` and ``t2`` element-wise. Only integer and boolean types are handled. If ``t1.shape!=t2.shape``, they must be broadcastable to a common shape (which becomes the shape of the output) :param t1: The first operand involved in the operation :type t1: DNDarray or scalar :param t2: The second operand involved in the operation :type t2: DNDarray or scalar :param out: The output array. It must have a shape that the inputs broadcast to and matching split axis. If not provided, a freshly allocated array is returned. :type out: DNDarray, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out` array will be set to the added value. Elsewhere, the `out` array will retain its original value. If an uninitialized `out` array is created via the default `out=None`, locations within it where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out` array. :type where: DNDarray, optional .. rubric:: Examples >>> ht.bitwise_and(13, 17) DNDarray(1, dtype=ht.int64, device=cpu:0, split=None) >>> ht.bitwise_and(14, 13) DNDarray(12, dtype=ht.int64, device=cpu:0, split=None) >>> ht.bitwise_and(ht.array([14, 3]), 13) DNDarray([12, 1], dtype=ht.int64, device=cpu:0, split=None) >>> ht.bitwise_and(ht.array([11, 7]), ht.array([4, 25])) DNDarray([0, 1], dtype=ht.int64, device=cpu:0, split=None) >>> ht.bitwise_and(ht.array([2, 5, 255]), ht.array([3, 14, 16])) DNDarray([ 2, 4, 16], dtype=ht.int64, device=cpu:0, split=None) >>> ht.bitwise_and(ht.array([True, True]), ht.array([False, True])) DNDarray([False, True], dtype=ht.bool, device=cpu:0, split=None) .. function:: bitwise_or(t1: Union[heat.core.dndarray.DNDarray, float], t2: Union[heat.core.dndarray.DNDarray, float], /, out: Optional[heat.core.dndarray.DNDarray] = None, *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> heat.core.dndarray.DNDarray Compute the bit-wise OR of two :class:`~heat.core.dndarray.DNDarray` ``t1`` and ``t2`` element-wise. Only integer and boolean types are handled. If ``t1.shape!=t2.shape``, they must be broadcastable to a common shape (which becomes the shape of the output) :param t1: The first operand involved in the operation :type t1: DNDarray or scalar :param t2: The second operand involved in the operation :type t2: DNDarray or scalar :param out: The output array. It must have a shape that the inputs broadcast to and matching split axis. If not provided, a freshly allocated array is returned. :type out: DNDarray, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out` array will be set to the added value. Elsewhere, the `out` array will retain its original value. If an uninitialized `out` array is created via the default `out=None`, locations within it where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out` array. :type where: DNDarray, optional .. rubric:: Examples >>> ht.bitwise_or(13, 16) DNDarray(29, dtype=ht.int64, device=cpu:0, split=None) >>> ht.bitwise_or(32, 2) DNDarray(34, dtype=ht.int64, device=cpu:0, split=None) >>> ht.bitwise_or(ht.array([33, 4]), 1) DNDarray([33, 5], dtype=ht.int64, device=cpu:0, split=None) >>> ht.bitwise_or(ht.array([33, 4]), ht.array([1, 2])) DNDarray([33, 6], dtype=ht.int64, device=cpu:0, split=None) >>> ht.bitwise_or(ht.array([2, 5, 255]), ht.array([4, 4, 4])) DNDarray([ 6, 5, 255], dtype=ht.int64, device=cpu:0, split=None) >>> ht.bitwise_or(ht.array([2, 5, 255, 2147483647], dtype=ht.int32), ht.array([4, 4, 4, 2147483647], dtype=ht.int32)) DNDarray([ 6, 5, 255, 2147483647], dtype=ht.int32, device=cpu:0, split=None) >>> ht.bitwise_or(ht.array([True, True]), ht.array([False, True])) DNDarray([True, True], dtype=ht.bool, device=cpu:0, split=None) .. function:: bitwise_xor(t1: Union[heat.core.dndarray.DNDarray, float], t2: Union[heat.core.dndarray.DNDarray, float], /, out: Optional[heat.core.dndarray.DNDarray] = None, *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> heat.core.dndarray.DNDarray Compute the bit-wise XOR of two arrays ``t1`` and ``t2`` element-wise. Only integer and boolean types are handled. If ``x1.shape!=x2.shape``, they must be broadcastable to a common shape (which becomes the shape of the output). :param t1: The first operand involved in the operation :type t1: DNDarray or scalar :param t2: The second operand involved in the operation :type t2: DNDarray or scalar :param out: The output array. It must have a shape that the inputs broadcast to and matching split axis. If not provided, a freshly allocated array is returned. :type out: DNDarray, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out` array will be set to the added value. Elsewhere, the `out` array will retain its original value. If an uninitialized `out` array is created via the default `out=None`, locations within it where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out` array. :type where: DNDarray, optional .. rubric:: Examples >>> ht.bitwise_xor(13, 17) DNDarray(28, dtype=ht.int64, device=cpu:0, split=None) >>> ht.bitwise_xor(31, 5) DNDarray(26, dtype=ht.int64, device=cpu:0, split=None) >>> ht.bitwise_xor(ht.array([31, 3]), 5) DNDarray([26, 6], dtype=ht.int64, device=cpu:0, split=None) >>> ht.bitwise_xor(ht.array([31, 3]), ht.array([5, 6])) DNDarray([26, 5], dtype=ht.int64, device=cpu:0, split=None) >>> ht.bitwise_xor(ht.array([True, True]), ht.array([False, True])) DNDarray([ True, False], dtype=ht.bool, device=cpu:0, split=None) .. function:: copysign(a: heat.core.dndarray.DNDarray, b: Union[heat.core.dndarray.DNDarray, float, int], /, out: Optional[heat.core.dndarray.DNDarray] = None, *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> heat.core.dndarray.DNDarray Create a new floating-point tensor with the magnitude of 'a' and the sign of 'b', element-wise :param a: The input array :type a: DNDarray :param b: value(s) whose signbit(s) are applied to the magnitudes in 'a' :type b: DNDarray or Number :param out: The output array. It must have a shape that the inputs broadcast to and matching split axis. If not provided, a freshly allocated array is returned. :type out: DNDarray, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out` array will be set to the divided value. Elsewhere, the `out` array will retain its original value. If an uninitialized `out` array is created via the default `out=None`, locations within it where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out` array. :type where: DNDarray, optional .. rubric:: Examples >>> ht.copysign(ht.array([3, 2, -8, -2, 4]), 1) DNDarray([3, 2, 8, 2, 4], dtype=ht.int64, device=cpu:0, split=None) >>> ht.copysign(ht.array([3.0, 2.0, -8.0, -2.0, 4.0]), ht.array([1.0, -1.0, 1.0, -1.0, 1.0])) DNDarray([ 3., -2., 8., -2., 4.], dtype=ht.float32, device=cpu:0, split=None) .. function:: cumprod(a: heat.core.dndarray.DNDarray, axis: int, dtype: heat.core.types.datatype = None, out=None) -> heat.core.dndarray.DNDarray Return the cumulative product of elements along a given axis. :param a: Input array. :type a: DNDarray :param axis: Axis along which the cumulative product is computed. :type axis: int :param dtype: Type of the returned array, as well as of the accumulator in which the elements are multiplied. If ``dtype`` is not specified, it defaults to the datatype of ``a``, unless ``a`` has an integer dtype with a precision less than that of the default platform integer. In that case, the default platform integer is used instead. :type dtype: datatype, optional :param out: Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type of the resulting values will be cast if necessary. :type out: DNDarray, optional .. rubric:: Examples >>> a = ht.full((3, 3), 2) >>> ht.cumprod(a, 0) DNDarray([[2., 2., 2.], [4., 4., 4.], [8., 8., 8.]], dtype=ht.float32, device=cpu:0, split=None) .. data:: cumproduct Alias for :py:func:`cumprod` .. function:: cumsum(a: heat.core.dndarray.DNDarray, axis: int, dtype: heat.core.types.datatype = None, out=None) -> heat.core.dndarray.DNDarray Return the cumulative sum of the elements along a given axis. :param a: Input array. :type a: DNDarray :param axis: Axis along which the cumulative sum is computed. :type axis: int :param dtype: Type of the returned array and of the accumulator in which the elements are summed. If ``dtype`` is not specified, it defaults to the datatype of ``a``, unless ``a`` has an integer dtype with a precision less than that of the default platform integer. In that case, the default platform integer is used. :type dtype: datatype, optional :param out: Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. :type out: DNDarray, optional .. rubric:: Examples >>> a = ht.ones((3, 3)) >>> ht.cumsum(a, 0) DNDarray([[1., 1., 1.], [2., 2., 2.], [3., 3., 3.]], dtype=ht.float32, device=cpu:0, split=None) .. function:: diff(a: heat.core.dndarray.DNDarray, n: int = 1, axis: int = -1, prepend: Union[int, float, heat.core.dndarray.DNDarray] = None, append: Union[int, float, heat.core.dndarray.DNDarray] = None) -> heat.core.dndarray.DNDarray Calculate the n-th discrete difference along the given axis. The first difference is given by ``out[i]=a[i+1]-a[i]`` along the given axis, higher differences are calculated by using diff recursively. The shape of the output is the same as ``a`` except along axis where the dimension is smaller by ``n``. The datatype of the output is the same as the datatype of the difference between any two elements of ``a``. The split does not change. The output array is balanced. :param a: Input array :type a: DNDarray :param n: The number of times values are differenced. If zero, the input is returned as-is. ``n=2`` is equivalent to ``diff(diff(a))`` :type n: int, optional :param axis: The axis along which the difference is taken, default is the last axis. :type axis: int, optional :param prepend: Value to prepend along axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match a except along axis. :type prepend: Union[int, float, DNDarray] :param append: Values to append along axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match a except along axis. :type append: Union[int, float, DNDarray] .. function:: div(t1: Union[heat.core.dndarray.DNDarray, float], t2: Union[heat.core.dndarray.DNDarray, float], /, out: Optional[heat.core.dndarray.DNDarray] = None, *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> heat.core.dndarray.DNDarray Element-wise true division of values of operand ``t1`` by values of operands ``t2`` (i.e ``t1/t2``). Operation is not commutative. :param t1: The first operand whose values are divided. :type t1: DNDarray or scalar :param t2: The second operand by whose values is divided. :type t2: DNDarray or scalar :param out: The output array. It must have a shape that the inputs broadcast to and matching split axis. If not provided, a freshly allocated array is returned. :type out: DNDarray, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out` array will be set to the divided value. Elsewhere, the `out` array will retain its original value. If an uninitialized `out` array is created via the default `out=None`, locations within it where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out` array. :type where: DNDarray, optional .. rubric:: Example >>> ht.div(2.0, 2.0) DNDarray(1., dtype=ht.float32, device=cpu:0, split=None) >>> T1 = ht.float32([[1, 2], [3, 4]]) >>> T2 = ht.float32([[2, 2], [2, 2]]) >>> ht.div(T1, T2) DNDarray([[0.5000, 1.0000], [1.5000, 2.0000]], dtype=ht.float32, device=cpu:0, split=None) >>> s = 2.0 >>> ht.div(s, T1) DNDarray([[2.0000, 1.0000], [0.6667, 0.5000]], dtype=ht.float32, device=cpu:0, split=None) .. data:: divide Alias for :py:func:`div` .. function:: divmod(t1: Union[heat.core.dndarray.DNDarray, float], t2: Union[heat.core.dndarray.DNDarray, float], out1: heat.core.dndarray.DNDarray = None, out2: heat.core.dndarray.DNDarray = None, /, out: Tuple[heat.core.dndarray.DNDarray, heat.core.dndarray.DNDarray] = (None, None), *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> Tuple[heat.core.dndarray.DNDarray, heat.core.dndarray.DNDarray] Element-wise division remainder and quotient from an integer division of values of operand ``t1`` by values of operand ``t2`` (i.e. C Library function divmod). Result has the sign as the dividend ``t1``. Operation is not commutative. :param t1: The first operand whose values are divided (may be floats) :type t1: DNDarray or scalar :param t2: The second operand by whose values is divided (may be floats) :type t2: DNDarray or scalar :param out1: The output array for the quotient. It must have a shape that the inputs broadcast to and matching split axis. If not provided, a freshly allocated array is returned. If provided, it must be of the same shape as the expected output. Only one of out1 and out can be provided. :type out1: DNDarray, optional :param out2: The output array for the remainder. It must have a shape that the inputs broadcast to and matching split axis. If not provided, a freshly allocated array is returned. If provided, it must be of the same shape as the expected output. Only one of out2 and out can be provided. :type out2: DNDarray, optional :param out: Tuple of two output arrays (quotient, remainder), respectively. Both must have a shape that the inputs broadcast to and matching split axis. If not provided, a freshly allocated array is returned. If provided, they must be of the same shape as the expected output. out1 and out2 cannot be used at the same time. :type out: tuple of two DNDarrays, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out1` array will be set to the quotient value and the `out2` array will be set to the remainder value. Elsewhere, the `out1` and `out2` arrays will retain their original value. If an uninitialized `out1` and `out2` array is created via the default `out1=None` and `out2=None`, locations within them where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out1` and `out2` arrays. :type where: DNDarray, optional .. rubric:: Examples >>> ht.divmod(2.0, 2.0) (DNDarray(1., dtype=ht.float32, device=cpu:0, split=None), DNDarray(0., dtype=ht.float32, device=cpu:0, split=None)) >>> T1 = ht.float32([[1, 2], [3, 4]]) >>> T2 = ht.float32([[2, 2], [2, 2]]) >>> ht.divmod(T1, T2) (DNDarray([[0., 1.], [1., 2.]], dtype=ht.float32, device=cpu:0, split=None), DNDarray([[1., 0.], [1., 0.]], dtype=ht.float32, device=cpu:0, split=None)) >>> s = 2.0 >>> ht.divmod(s, T1) (DNDarray([[2., 1.], [0., 0.]], dtype=ht.float32, device=cpu:0, split=None), DNDarray([[0., 0.], [2., 2.]], dtype=ht.float32, device=cpu:0, split=None)) .. function:: floordiv(t1: Union[heat.core.dndarray.DNDarray, float], t2: Union[heat.core.dndarray.DNDarray, float], /, out: Optional[heat.core.dndarray.DNDarray] = None, *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> heat.core.dndarray.DNDarray Element-wise floor division of value(s) of operand ``t1`` by value(s) of operand ``t2`` (i.e. ``t1//t2``), not commutative. :param t1: The first operand whose values are divided :type t1: DNDarray or scalar :param t2: The second operand by whose values is divided :type t2: DNDarray or scalar :param out: The output array. It must have a shape that the inputs broadcast to and matching split axis. If not provided, a freshly allocated array is returned. :type out: DNDarray, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out` array will be set to the divided value. Elsewhere, the `out` array will retain its original value. If an uninitialized `out` array is created via the default `out=None`, locations within it where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out` array. :type where: DNDarray, optional .. rubric:: Examples >>> T1 = ht.float32([[1.7, 2.0], [1.9, 4.2]]) >>> ht.floordiv(T1, 1) DNDarray([[1., 2.], [1., 4.]], dtype=ht.float64, device=cpu:0, split=None) >>> T2 = ht.float32([1.5, 2.5]) >>> ht.floordiv(T1, T2) DNDarray([[1., 0.], [1., 1.]], dtype=ht.float32, device=cpu:0, split=None) .. data:: floor_divide Alias for :py:func:`floordiv` .. function:: fmod(t1: Union[heat.core.dndarray.DNDarray, float], t2: Union[heat.core.dndarray.DNDarray, float], /, out: Optional[heat.core.dndarray.DNDarray] = None, *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> heat.core.dndarray.DNDarray Element-wise division remainder of values of operand ``t1`` by values of operand ``t2`` (i.e. C Library function fmod). Result has the sign as the dividend ``t1``. Operation is not commutative. :param t1: The first operand whose values are divided (may be floats) :type t1: DNDarray or scalar :param t2: The second operand by whose values is divided (may be floats) :type t2: DNDarray or scalar :param out: The output array. It must have a shape that the inputs broadcast to and matching split axis. If not provided, a freshly allocated array is returned. If provided, it must be of the same shape as the expected output. :type out: DNDarray, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out` array will be set to the divided value. Elsewhere, the `out` array will retain its original value. If an uninitialized `out` array is created via the default `out=None`, locations within it where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out` array. :type where: DNDarray, optional .. rubric:: Examples >>> ht.fmod(2.0, 2.0) DNDarray(0., dtype=ht.float32, device=cpu:0, split=None) >>> T1 = ht.float32([[1, 2], [3, 4]]) >>> T2 = ht.float32([[2, 2], [2, 2]]) >>> ht.fmod(T1, T2) DNDarray([[1., 0.], [1., 0.]], dtype=ht.float32, device=cpu:0, split=None) >>> s = 2.0 >>> ht.fmod(s, T1) DNDarray([[0., 0.], [2., 2.]], dtype=ht.float32, device=cpu:0, split=None) .. function:: gcd(a: heat.core.dndarray.DNDarray, b: heat.core.dndarray.DNDarray, /, out: Optional[heat.core.dndarray.DNDarray] = None, *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> heat.core.dndarray.DNDarray Returns the greatest common divisor of |a| and |b| element-wise. :param a: The first input array, must be of integer type :type a: DNDarray :param b: the second input array, must be of integer type :type b: DNDarray :param out: The output array. It must have a shape that the inputs broadcast to and matching split axis. If not provided, a freshly allocated array is returned. :type out: DNDarray, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out` array will be set to the divided value. Elsewhere, the `out` array will retain its original value. If an uninitialized `out` array is created via the default `out=None`, locations within it where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out` array. :type where: DNDarray, optional .. rubric:: Examples >>> import heat as ht >>> T1 = ht.int(ht.ones(3)) * 9 >>> T2 = ht.arange(3) + 1 >>> ht.gcd(T1, T2) DNDarray([1, 1, 3], dtype=ht.int32, device=cpu:0, split=None) .. function:: hypot(t1: heat.core.dndarray.DNDarray, t2: heat.core.dndarray.DNDarray, /, out: Optional[heat.core.dndarray.DNDarray] = None, *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> heat.core.dndarray.DNDarray Given the 'legs' of a right triangle, return its hypotenuse. Equivalent to :math:`sqrt(a^2 + b^2)`, element-wise. :param t1: The first input array :type t1: DNDarray :param t2: the second input array :type t2: DNDarray :param out: The output array. It must have a shape that the inputs broadcast to and matching split axis. If not provided, a freshly allocated array is returned. :type out: DNDarray, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out` array will be set to the divided value. Elsewhere, the `out` array will retain its original value. If an uninitialized `out` array is created via the default `out=None`, locations within it where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out` array. :type where: DNDarray, optional .. rubric:: Examples >>> a = ht.array([2.0]) >>> b = ht.array([1.0, 3.0, 3.0]) >>> ht.hypot(a, b) DNDarray([2.2361, 3.6056, 3.6056], dtype=ht.float32, device=cpu:0, split=None) .. function:: invert(a: heat.core.dndarray.DNDarray, /, out: Optional[heat.core.dndarray.DNDarray] = None) -> heat.core.dndarray.DNDarray Computes the bitwise NOT of the given input :class:`~heat.core.dndarray.DNDarray`. The input array must be of integral or Boolean types. For boolean arrays, it computes the logical NOT. Bitwise_not is an alias for invert. :param a: The input array to invert. Must be of integral or Boolean types :type a: DNDarray :param out: Alternative output array in which to place the result. It must have the same shape as the expected output. The dtype of the output will be the one of the input array, unless it is logical, in which case it will be casted to int8. If not provided or None, a freshly- allocated array is returned. :type out: DNDarray, optional .. rubric:: Examples >>> ht.invert(ht.array([13], dtype=ht.uint8)) DNDarray([242], dtype=ht.uint8, device=cpu:0, split=None) >>> ht.bitwise_not(ht.array([-1, -2, 3], dtype=ht.int8)) DNDarray([ 0, 1, -4], dtype=ht.int8, device=cpu:0, split=None) .. data:: bitwise_not Alias for :py:func:`invert` .. function:: lcm(a: heat.core.dndarray.DNDarray, b: heat.core.dndarray.DNDarray, /, out: Optional[heat.core.dndarray.DNDarray] = None, *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> heat.core.dndarray.DNDarray Returns the lowest common multiple of |a| and |b| element-wise. :param a: The first input (array), must be of integer type :type a: DNDarray or scalar :param b: the second input (array), must be of integer type :type b: DNDarray or scalar :param out: The output array. It must have a shape that the inputs broadcast to and matching split axis. If not provided, a freshly allocated array is returned. :type out: DNDarray, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out` array will be set to the divided value. Elsewhere, the `out` array will retain its original value. If an uninitialized `out` array is created via the default `out=None`, locations within it where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out` array. :type where: DNDarray, optional .. rubric:: Examples >>> a = ht.array([6, 12, 15]) >>> b = ht.array([3, 4, 5]) >>> ht.lcm(a, b) DNDarray([ 6, 12, 15], dtype=ht.int64, device=cpu:0, split=None) >>> s = 2 >>> ht.lcm(s, a) DNDarray([ 6, 12, 30], dtype=ht.int64, device=cpu:0, split=None) >>> ht.lcm(b, s) DNDarray([ 6, 4, 10], dtype=ht.int64, device=cpu:0, split=None) .. function:: left_shift(t1: heat.core.dndarray.DNDarray, t2: Union[heat.core.dndarray.DNDarray, float], /, out: Optional[heat.core.dndarray.DNDarray] = None, *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> heat.core.dndarray.DNDarray Shift the bits of an integer to the left. :param t1: Input array :type t1: DNDarray :param t2: Integer number of zero bits to add :type t2: DNDarray or float :param out: Output array for the result. Must have the same shape as the expected output. The dtype of the output will be the one of the input array, unless it is logical, in which case it will be casted to int8. If not provided or None, a freshly-allocated array is returned. :type out: DNDarray, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out` array will be set to the shifted value. Elsewhere, the `out` array will retain its original value. If an uninitialized `out` array is created via the default `out=None`, locations within it where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out` array. :type where: DNDarray, optional .. rubric:: Examples >>> ht.left_shift(ht.array([1, 2, 3]), 1) DNDarray([2, 4, 6], dtype=ht.int64, device=cpu:0, split=None) .. function:: mul(t1: Union[heat.core.dndarray.DNDarray, float], t2: Union[heat.core.dndarray.DNDarray, float], /, out: Optional[heat.core.dndarray.DNDarray] = None, *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> heat.core.dndarray.DNDarray Element-wise multiplication (NOT matrix multiplication) of values from two operands, commutative. Takes the first and second operand (scalar or :class:`~heat.core.dndarray.DNDarray`) whose elements are to be multiplied as argument. :param t1: The first operand involved in the multiplication :type t1: DNDarray or scalar :param t2: The second operand involved in the multiplication :type t2: DNDarray or scalar :param out: Output array. It must have a shape that the inputs broadcast to and matching split axis. If not provided or None, a freshly-allocated array is returned. :type out: DNDarray, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out` array will be set to the multiplied value. Elsewhere, the `out` array will retain its original value. If an uninitialized `out` array is created via the default `out=None`, locations within it where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out` array. :type where: DNDarray, optional .. rubric:: Examples >>> ht.mul(2.0, 4.0) DNDarray(8., dtype=ht.float32, device=cpu:0, split=None) >>> T1 = ht.float32([[1, 2], [3, 4]]) >>> s = 3.0 >>> ht.mul(T1, s) DNDarray([[ 3., 6.], [ 9., 12.]], dtype=ht.float32, device=cpu:0, split=None) >>> T2 = ht.float32([[2, 2], [2, 2]]) >>> ht.mul(T1, T2) DNDarray([[2., 4.], [6., 8.]], dtype=ht.float32, device=cpu:0, split=None) .. data:: multiply Alias for :py:func:`mul` .. function:: nan_to_num(a: heat.core.dndarray.DNDarray, nan: float = 0.0, posinf: float = None, neginf: float = None, out: Optional[heat.core.dndarray.DNDarray] = None) -> heat.core.dndarray.DNDarray Replaces NaNs, positive infinity values, and negative infinity values in the input 'a' with the values specified by nan, posinf, and neginf, respectively. By default, NaNs are replaced with zero, positive infinity is replaced with the greatest finite value representable by input's dtype, and negative infinity is replaced with the least finite value representable by input's dtype. :param a: Input array. :type a: DNDarray :param nan: Value to be used to replace NaNs. Default value is 0.0. :type nan: float, optional :param posinf: Value to replace positive infinity values with. If None, positive infinity values are replaced with the greatest finite value of the input's dtype. Default value is None. :type posinf: float, optional :param neginf: Value to replace negative infinity values with. If None, negative infinity values are replaced with the greatest negative finite value of the input's dtype. Default value is None. :type neginf: float, optional :param out: Alternative output array in which to place the result. It must have the same shape as the expected output, but the datatype of the output values will be cast if necessary. :type out: DNDarray, optional .. rubric:: Examples >>> x = ht.array([float("nan"), float("inf"), -float("inf")]) >>> ht.nan_to_num(x) DNDarray([ 0.0000e+00, 3.4028e+38, -3.4028e+38], dtype=ht.float32, device=cpu:0, split=None) .. function:: nanprod(a: heat.core.dndarray.DNDarray, axis: Union[int, Tuple[int, Ellipsis]] = None, out: heat.core.dndarray.DNDarray = None, keepdims: bool = None) -> heat.core.dndarray.DNDarray Return the product of array elements over a given axis treating Not a Numbers (NaNs) as one. :param a: Input array. :type a: DNDarray :param axis: Axis or axes along which a product is performed. The default, ``axis=None``, will calculate the product of all the elements in the input array. If axis is negative it counts from the last to the first axis. If axis is a tuple of ints, a product is performed on all of the axes specified in the tuple instead of a single axis or all the axes as before. :type axis: None or int or Tuple[int,...], optional :param out: Alternative output array in which to place the result. It must have the same shape as the expected output, but the datatype of the output values will be cast if necessary. :type out: DNDarray, optional :param keepdims: If this is set to ``True``, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. :type keepdims: bool, optional .. rubric:: Examples >>> ht.nanprod(ht.array([4.0, ht.nan])) DNDarray(4., dtype=ht.float32, device=cpu:0, split=None) >>> ht.nanprod(ht.array([ [1.,ht.nan], [3.,4.]])) DNDarray(12., dtype=ht.float32, device=cpu:0, split=None) >>> ht.nanprod(ht.array([ [1.,ht.nan], [ht.nan,4.] ]), axis=1) DNDarray([ 1., 4.], dtype=ht.float32, device=cpu:0, split=None) .. function:: nansum(a: heat.core.dndarray.DNDarray, axis: Union[int, Tuple[int, Ellipsis]] = None, out: heat.core.dndarray.DNDarray = None, keepdims: bool = None) -> heat.core.dndarray.DNDarray Sum of array elements over a given axis treating Not a Numbers (NaNs) as zero. An array with the same shape as ``self.__array`` except for the specified axis which becomes one, e.g. ``a.shape=(1, 2, 3)`` => ``ht.ones((1, 2, 3)).sum(axis=1).shape=(1, 1, 3)`` :param a: Input array. :type a: DNDarray :param axis: Axis along which a sum is performed. The default, ``axis=None``, will sum all of the elements of the input array. If ``axis`` is negative it counts from the last to the first axis. If ``axis`` is a tuple of ints, a sum is performed on all of the axes specified in the tuple instead of a single axis or all the axes as before. :type axis: None or int or Tuple[int,...], optional :param out: Alternative output array in which to place the result. It must have the same shape as the expected output, but the datatype of the output values will be cast if necessary. :type out: DNDarray, optional :param keepdims: If this is set to ``True``, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. :type keepdims: bool, optional .. rubric:: Examples >>> ht.sum(ht.ones(2)) DNDarray(2., dtype=ht.float32, device=cpu:0, split=None) >>> ht.sum(ht.ones((3, 3))) DNDarray(9., dtype=ht.float32, device=cpu:0, split=None) >>> ht.sum(ht.ones((3, 3)).astype(ht.int)) DNDarray(9, dtype=ht.int64, device=cpu:0, split=None) >>> ht.sum(ht.ones((3, 2, 1)), axis=-3) DNDarray([[3.], [3.]], dtype=ht.float32, device=cpu:0, split=None) .. function:: neg(a: heat.core.dndarray.DNDarray, out: Optional[heat.core.dndarray.DNDarray] = None) -> heat.core.dndarray.DNDarray Element-wise negation of `a`. :param a: The input array. :type a: DNDarray :param out: The output array. It must have a shape that the inputs broadcast to :type out: DNDarray, optional .. rubric:: Examples >>> ht.neg(ht.array([-1, 1])) DNDarray([ 1, -1], dtype=ht.int64, device=cpu:0, split=None) >>> -ht.array([-1.0, 1.0]) DNDarray([ 1., -1.], dtype=ht.float32, device=cpu:0, split=None) .. data:: negative Alias for :py:func:`neg` .. function:: pos(a: heat.core.dndarray.DNDarray, out: Optional[heat.core.dndarray.DNDarray] = None) -> heat.core.dndarray.DNDarray Element-wise positive of `a`. :param a: The input array. :type a: DNDarray :param out: The output array. It must have a shape that the inputs broadcast to. :type out: DNDarray, optional .. rubric:: Notes Equivalent to a.copy(). .. rubric:: Examples >>> ht.pos(ht.array([-1, 1])) DNDarray([-1, 1], dtype=ht.int64, device=cpu:0, split=None) >>> +ht.array([-1.0, 1.0]) DNDarray([-1., 1.], dtype=ht.float32, device=cpu:0, split=None) .. data:: positive Alias for :py:func:`pos` .. function:: pow(t1: Union[heat.core.dndarray.DNDarray, float], t2: Union[heat.core.dndarray.DNDarray, float], /, out: Optional[heat.core.dndarray.DNDarray] = None, *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> heat.core.dndarray.DNDarray Element-wise power function of values of operand ``t1`` to the power of values of operand ``t2`` (i.e ``t1**t2``). Operation is not commutative. :param t1: The first operand whose values represent the base :type t1: DNDarray or scalar :param t2: The second operand whose values represent the exponent :type t2: DNDarray or scalar :param out: Output array. It must have a shape that the inputs broadcast to and matching split axis. If not provided or None, a freshly-allocated array is returned. :type out: DNDarray, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out` array will be set to the exponentiated value. Elsewhere, the `out` array will retain its original value. If an uninitialized `out` array is created via the default `out=None`, locations within it where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out` array. :type where: DNDarray, optional .. rubric:: Examples >>> ht.pow(3.0, 2.0) DNDarray(9., dtype=ht.float32, device=cpu:0, split=None) >>> T1 = ht.float32([[1, 2], [3, 4]]) >>> T2 = ht.float32([[3, 3], [2, 2]]) >>> ht.pow(T1, T2) DNDarray([[ 1., 8.], [ 9., 16.]], dtype=ht.float32, device=cpu:0, split=None) >>> s = 3.0 >>> ht.pow(T1, s) DNDarray([[ 1., 8.], [27., 64.]], dtype=ht.float32, device=cpu:0, split=None) .. data:: power Alias for :py:func:`pow` .. function:: prod(a: heat.core.dndarray.DNDarray, axis: Union[int, Tuple[int, Ellipsis]] = None, out: heat.core.dndarray.DNDarray = None, keepdims: bool = None) -> heat.core.dndarray.DNDarray Return the product of array elements over a given axis in form of a DNDarray shaped as a but with the specified axis removed. :param a: Input array. :type a: DNDarray :param axis: Axis or axes along which a product is performed. The default, ``axis=None``, will calculate the product of all the elements in the input array. If axis is negative it counts from the last to the first axis. If axis is a tuple of ints, a product is performed on all of the axes specified in the tuple instead of a single axis or all the axes as before. :type axis: None or int or Tuple[int,...], optional :param out: Alternative output array in which to place the result. It must have the same shape as the expected output, but the datatype of the output values will be cast if necessary. :type out: DNDarray, optional :param keepdims: If this is set to ``True``, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. :type keepdims: bool, optional .. rubric:: Examples >>> ht.prod(ht.array([1.0, 2.0])) DNDarray(2., dtype=ht.float32, device=cpu:0, split=None) >>> ht.prod(ht.array([ [1.,2.], [3.,4.]])) DNDarray(24., dtype=ht.float32, device=cpu:0, split=None) >>> ht.prod(ht.array([ [1.,2.], [3.,4.] ]), axis=1) DNDarray([ 2., 12.], dtype=ht.float32, device=cpu:0, split=None) .. function:: remainder(t1: Union[heat.core.dndarray.DNDarray, float], t2: Union[heat.core.dndarray.DNDarray, float], /, out: Optional[heat.core.dndarray.DNDarray] = None, *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> heat.core.dndarray.DNDarray Element-wise division remainder of values of operand ``t1`` by values of operand ``t2`` (i.e. ``t1%t2``). Result has the same sign as the divisor ``t2``. Operation is not commutative. :param t1: The first operand whose values are divided :type t1: DNDarray or scalar :param t2: The second operand by whose values is divided :type t2: DNDarray or scalar :param out: Output array. It must have a shape that the inputs broadcast to and matching split axis. If not provided, a freshly allocated array is returned. :type out: DNDarray, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out` array will be set to the divided value. Elsewhere, the `out` array will retain its original value. If an uninitialized `out` array is created via the default `out=None`, locations within it where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out` array. :type where: DNDarray, optional .. rubric:: Examples >>> ht.remainder(2, 2) DNDarray(0, dtype=ht.int64, device=cpu:0, split=None) >>> T1 = ht.int32([[1, 2], [3, 4]]) >>> T2 = ht.int32([[2, 2], [2, 2]]) >>> ht.remainder(T1, T2) DNDarray([[1, 0], [1, 0]], dtype=ht.int32, device=cpu:0, split=None) >>> s = 2 >>> ht.remainder(s, T1) DNDarray([[0, 0], [2, 2]], dtype=ht.int32, device=cpu:0, split=None) .. data:: mod Alias for :py:func:`remainder` .. function:: right_shift(t1: Union[heat.core.dndarray.DNDarray, float], t2: Union[heat.core.dndarray.DNDarray, float], /, out: Optional[heat.core.dndarray.DNDarray] = None, *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> heat.core.dndarray.DNDarray Shift the bits of an integer to the right. :param t1: Input array :type t1: DNDarray or scalar :param t2: Integer number of bits to remove :type t2: DNDarray or scalar :param out: Output array for the result. Must have the same shape as the expected output. The dtype of the output will be the one of the input array, unless it is logical, in which case it will be casted to int8. If not provided or None, a freshly-allocated array is returned. :type out: DNDarray, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out` array will be set to the shifted value. Elsewhere, the `out` array will retain its original value. If an uninitialized `out` array is created via the default `out=None`, locations within it where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out` array. :type where: DNDarray, optional .. rubric:: Examples >>> ht.right_shift(ht.array([1, 2, 3]), 1) DNDarray([0, 1, 1], dtype=ht.int64, device=cpu:0, split=None) .. function:: sub(t1: Union[heat.core.dndarray.DNDarray, float], t2: Union[heat.core.dndarray.DNDarray, float], /, out: Optional[heat.core.dndarray.DNDarray] = None, *, where: Union[bool, heat.core.dndarray.DNDarray] = True) -> heat.core.dndarray.DNDarray Element-wise subtraction of values of operand ``t2`` from values of operands ``t1`` (i.e ``t1-t2``). Operation is not commutative. :param t1: The first operand from which values are subtracted :type t1: DNDarray or scalar :param t2: The second operand whose values are subtracted :type t2: DNDarray or scalar :param out: Output array. It must have a shape that the inputs broadcast to and matching split axis. If not provided or None, a freshly-allocated array is returned. :type out: DNDarray, optional :param where: Condition to broadcast over the inputs. At locations where the condition is True, the `out` array will be set to the subtracted value. Elsewhere, the `out` array will retain its original value. If an uninitialized `out` array is created via the default `out=None`, locations within it where the condition is False will remain uninitialized. If distributed, the split axis (after broadcasting if required) must match that of the `out` array. :type where: DNDarray, optional .. rubric:: Examples >>> ht.sub(4.0, 1.0) DNDarray(3., dtype=ht.float32, device=cpu:0, split=None) >>> T1 = ht.float32([[1, 2], [3, 4]]) >>> T2 = ht.float32([[2, 2], [2, 2]]) >>> ht.sub(T1, T2) DNDarray([[-1., 0.], [ 1., 2.]], dtype=ht.float32, device=cpu:0, split=None) >>> s = 2.0 >>> ht.sub(s, T1) DNDarray([[ 1., 0.], [-1., -2.]], dtype=ht.float32, device=cpu:0, split=None) .. data:: subtract Alias for :py:func:`sub` .. function:: sum(a: heat.core.dndarray.DNDarray, axis: Union[int, Tuple[int, Ellipsis]] = None, out: heat.core.dndarray.DNDarray = None, keepdims: bool = None) -> heat.core.dndarray.DNDarray Sum of array elements over a given axis. An array with the same shape as ``self.__array`` except for the specified axis which becomes one, e.g. ``a.shape=(1, 2, 3)`` => ``ht.ones((1, 2, 3)).sum(axis=1).shape=(1, 1, 3)`` :param a: Input array. :type a: DNDarray :param axis: Axis along which a sum is performed. The default, ``axis=None``, will sum all of the elements of the input array. If ``axis`` is negative it counts from the last to the first axis. If ``axis`` is a tuple of ints, a sum is performed on all of the axes specified in the tuple instead of a single axis or all the axes as before. :type axis: None or int or Tuple[int,...], optional :param out: Alternative output array in which to place the result. It must have the same shape as the expected output, but the datatype of the output values will be cast if necessary. :type out: DNDarray, optional :param keepdims: If this is set to ``True``, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. :type keepdims: bool, optional .. rubric:: Examples >>> ht.sum(ht.ones(2)) DNDarray(2., dtype=ht.float32, device=cpu:0, split=None) >>> ht.sum(ht.ones((3, 3))) DNDarray(9., dtype=ht.float32, device=cpu:0, split=None) >>> ht.sum(ht.ones((3, 3)).astype(ht.int)) DNDarray(9, dtype=ht.int64, device=cpu:0, split=None) >>> ht.sum(ht.ones((3, 2, 1)), axis=-3) DNDarray([[3.], [3.]], dtype=ht.float32, device=cpu:0, split=None)