Programming Articles - Page 771 of 3363

Return the truth value of an array greater than equal to another element-wise in Numpy

AmitDiwan
Updated on 08-Feb-2022 10:24:43

432 Views

To return the truth value of an array greater than equal to another element-wise, use the numpy.greater_equal() method in Python Numpy. Return value is either True or False. Returns an output array, element-wise comparison of x1 and x2. Typically, of type bool, unless dtype=object is passed. This is a scalar if both x1 and x2 are scalars.The out is a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length ... Read More

Return the truth value of an array greater than another element-wise in Numpy

AmitDiwan
Updated on 08-Feb-2022 10:22:08

1K+ Views

To return the truth value of an array greater than another element-wise, use the numpy.greater() method in Python Numpy. Return value is either True or False. Returns an output array, elementwise comparison of x1 and x2. Typically of type bool, unless dtype=object is passed. This is a scalar if both x1 and x2 are scalars.The out is a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to ... Read More

Return the greatest common divisor and lowest common multiple in Numpy

AmitDiwan
Updated on 08-Feb-2022 10:18:36

520 Views

To return the greatest common divisor, use the numpy.gcd() method in Python Numpy. The parameters are arrays of values. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).To return the lowest common multiple, use the numpy.lcm() method in Python Numpy. The greatest common divisor of the absolute value of the inputs This is a scalar if both x1 and x2 are scalars.StepsAt first, import the required library −import numpy as npTo return the greatest common divisor, use the numpy.gcd() method in Python Numpy. The parameters are arrays of values. If ... Read More

Reduce a multi-dimensional array and add elements along axis 0 in Numpy

AmitDiwan
Updated on 08-Feb-2022 10:13:41

184 Views

To reduce a multi-dimensional array, use the np.ufunc.reduce() method in Python Numpy. Here, we have used add.reduce() to reduce it to the addition of elements. The axis 0 is set using the "axis" parameter.The numpy.ufunc has functions that operate element by element on whole arrays. The ufuncs are written in C (for speed) and linked into Python with NumPy's ufunc facility. A universal function (or ufunc for short) is a function that operates on ndarrays in an element-by-element fashion, supporting array broadcasting, type casting, and several other standard features. That is, a ufunc is a "vectorized" wrapper for a function ... Read More

Reduce a multi-dimensional array and add elements along specific axis in Numpy

AmitDiwan
Updated on 08-Feb-2022 10:11:05

291 Views

To reduce a multi-dimensional array, use the np.ufunc.reduce() method in Python Numpy. Here, we have used add.reduce() to reduce it to the addition of elements. The axis is set using the "axis" parameter.A universal function (ufunc) is a function that operates on ndarrays in an element-by-element fashion, supporting array broadcasting, type casting, and several other standard features. That is, a ufunc is a “vectorized” wrapper for a function that takes a fixed number of specific inputs and produces a fixed number of specific outputs. The numpy.ufunc has functions that operate element by element on whole arrays. The ufuncs are written ... Read More

Return the non-negative square-root of an array element-wise in Numpy

AmitDiwan
Updated on 08-Feb-2022 10:08:15

298 Views

To return the non-negative square-root of an array, element-wise, use the numpy.sqrt() method in Python Numpy.An array of the same shape as x, containing the positive square-root of each element in x. If any element in x is complex, a complex array is returned (and the square-roots of negative reals are calculated). If all of the elements in x are real, so is y, with negative elements returning nan. If out was provided, y is a reference to it. This is a scalar if x is a scalar.The out is a location into which the result is stored. If provided, ... Read More

Return the natural logarithm of one plus the input array element-wise in Numpy

AmitDiwan
Updated on 08-Feb-2022 10:06:14

208 Views

To return the natural logarithm of one plus the input array, element-wise., use the numpy.log1p() method in Python Numpy. It calculates log(1 + x).For complex-valued input, log1p is a complex analytical function that has a branch cut [-inf, -1] and is continuous from above on it. log1p handles the floating-point negative zero as an infinitesimal negative number, conforming to the C99 standard.StepsAt first, import the required library −import numpy as npCreate an array using the array() method −arr = np.array([1e-15, 10000, 1e-99]) Display the array −print("Array...", arr)Get the type of the array −print("Our Array type...", arr.dtype) Get the dimensions of ... Read More

Return the base 10 logarithm of the input array element-wise in Numpy

AmitDiwan
Updated on 08-Feb-2022 10:03:06

2K+ Views

To return the base 10 logarithm of the input array, element-wise, use the numpy.log10() method in Python Numpy. For real-valued input data types, log10 always returns real output. For each value that cannot be expressed as a real number or infinity, it yields nan and sets the invalid floating point error flag.Returns the logarithm to the base 10 of x, element-wise. NaNs are returned where x is negative. This is a scalar if x is a scalar.The out is a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If ... Read More

Compute the Heaviside step function in Numpy

AmitDiwan
Updated on 08-Feb-2022 10:00:38

845 Views

To compute the Heaviside step function, use the numpy.heaviside() method in Python Numpy. The 1st parameter is the input array. The 2nd parameter is the value of the function when array element is 0. Returns the output array, element-wise Heaviside step function of x1. This is a scalar if both x1 and x2 are scalars.The Heaviside step function is defined as −0 if x1 < 0 heaviside(x1, x2) = x2 if x1 == 0 1 if x1 > 0where x2 is often taken to be 0.5, but 0 and 1 are also sometimes used.StepsAt first, import the required library −import ... Read More

Return an element-wise indication of the sign of complex types in Numpy

AmitDiwan
Updated on 08-Feb-2022 09:57:26

206 Views

To return an element-wise indication of the sign of complex types, use the numpy.sign() method in Python Numpy.The sign function returns -1 if x < 0, 0 if x==0, 1 if x > 0. nan is returned for nan inputs. For complex inputs, the sign function returns sign(x.real) + 0j if x.real != 0 else sign(x.imag) + 0j.The complex(nan, 0) is returned for complex nan inputs. There is more than one definition of sign in common use for complex numbers. The definition used here is equivalent to x/x*x which is different from a common alternative, x/|x|.StepsAt first, import the required ... Read More

Advertisements