NumPy positive()

The numpy.positive() function returns the numerical positive value of each element in the input array. It is an identity function that simply returns +x for each element.

Syntax

</>
Copy
numpy.positive(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)

Parameters

ParameterTypeDescription
xarray_like or scalarInput array or scalar whose positive values are returned.
outndarray, None, or tuple of ndarray and None, optionalOptional output array where the result is stored. If None, a new array is created.
wherearray_like, optionalBoolean mask specifying which elements to compute. Elements where where=False retain their original value.
castingstr, optionalDefines the casting behavior when computing the function.
orderstr, optionalMemory layout order of the output array.
dtypedata-type, optionalDefines the data type of the output array.
subokbool, optionalDetermines if subclasses of ndarray are preserved in the output.

Return Value

Returns an array with the positive values of the input array elements. If the input is a scalar, a scalar is returned.


Examples

1. Applying numpy.positive() to a Single Value

In this example, we apply numpy.positive() to a scalar value.

</>
Copy
import numpy as np

# Define a scalar value
value = -5

# Apply numpy.positive()
result = np.positive(value)

# Print the result
print("Positive value:", result)

Output:

Positive value: -5