Numpy Articles

Page 59 of 81

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

AmitDiwan
AmitDiwan
Updated on 08-Feb-2022 245 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

Round elements of the array to the nearest integer in Numpy

AmitDiwan
AmitDiwan
Updated on 08-Feb-2022 8K+ Views

To round elements of the array to the nearest integer, use the numpy.rint() method in Python Numpy. For values exactly halfway between rounded decimal values, NumPy rounds to the nearest even value.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 the number of outputs.The condition is broadcast over the input. At locations where the condition is True, the out array will be set ...

Read More

Calculate the absolute value of complex numbers in Numpy

AmitDiwan
AmitDiwan
Updated on 08-Feb-2022 1K+ Views

To return the absolute value of complex values, use the numpy.absolute() method in Python Numpy. 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 the number of outputs.The condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if ...

Read More

Return the element-wise remainder of division in Numpy

AmitDiwan
AmitDiwan
Updated on 08-Feb-2022 477 Views

To return the element-wise remainder of division, use the numpy.remainder() method in Python Numpy. Here, the 1st parameter is the Dividend array. The 2nd parameter is the Divisor array.Computes the remainder complementary to the floor_divide function. It is equivalent to the Python modulus operator''x1 % x2'' and has the same sign as the divisor x2. The MATLAB function equivalent to np.remainder is mod.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 ...

Read More

Raise the bases to different exponents in Numpy

AmitDiwan
AmitDiwan
Updated on 08-Feb-2022 807 Views

To raise the bases to different exponents, use the numpy.power() method in Python. Here, the 1st parameter is the base and the 2nd exponents.Raise each base in x1 to the positionally-corresponding power in x2. x1 and x2 must be broadcastable to the same shape. An integer type raised to a negative integer power will raise a ValueError. Negative values raised to a non-integral value will return nan. To get complex results, cast the input to complex, or specify the dtype to be complex.The condition is broadcast over the input. At locations where the condition is True, the out array will ...

Read More

Return the floor of the input in Numpy

AmitDiwan
AmitDiwan
Updated on 08-Feb-2022 256 Views

To return the floor of the input, use the numpy.floor() method in Python Numpy. The floor of the scalar x is the largest integer i, such that i

Read More

Return the floor of the array elements in Numpy

AmitDiwan
AmitDiwan
Updated on 08-Feb-2022 215 Views

To return the floor of the array elements, element-wise, use the numpy.floor() method in Python Numpy. The floor of the scalar x is the largest integer i, such that i

Read More

Return a 2-D array with ones on the diagonal and zeros elsewhere in Numpy

AmitDiwan
AmitDiwan
Updated on 08-Feb-2022 436 Views

The numpy.eye() returns a 2-D array with 1’s as the diagonal and 0’s elsewhere. Here, the 1st parameter means the "Number of rows in the output" i.e. 4 means 4x4 array. The 2nd parameter is the number of columns in the output.The function eye() returns an array where all elements are equal to zero, except for the k-th diagonal, whose values are equal to one. The dtype is the data-type of the returned array. The order suggests whether the output should be stored in row-major (C-style) or column-major (Fortran-style) order in memory.The like parameter is a reference object to allow ...

Read More

Return a new array with the same shape and type as a given array and change the order to C style in Numpy

AmitDiwan
AmitDiwan
Updated on 08-Feb-2022 174 Views

To return a new array with the same shape and type as a given array, use the numpy.empty_like() method in Python Numpy. It returns the array of uninitialized (arbitrary) data with the same shape and type as prototype. The 1st parameter here is the shape and data-type of prototype(array-like) that define these same attributes of the returned array. We have set the order to 'C' style using the "order" parameter.The order overrides the memory layout of the result. ‘C’ means C-order, ‘F’ means F-order, ‘A’ means ‘F’ if prototype is Fortran contiguous, ‘C’ otherwise. ‘K’ means match the layout of ...

Read More

Return a new array with the same shape and type as a given array and change the order to K style in Numpy

AmitDiwan
AmitDiwan
Updated on 08-Feb-2022 253 Views

To return a new array with the same shape and type as a given array, use the numpy.empty_like() method in Python Numpy. It returns the array of uninitialized (arbitrary) data with the same shape and type as prototype. The 1st parameter here is the shape and data-type of prototype(array-like) that define these same attributes of the returned array. We have set the order to 'K' style using the "order" parameter. ‘K’ means match the layout of prototype as closely as possible.The order overrides the memory layout of the result. ‘C’ means C-order, ‘F’ means F-order, ‘A’ means ‘F’ if prototype ...

Read More
Showing 581–590 of 802 articles
« Prev 1 57 58 59 60 61 81 Next »
Advertisements