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
| Parameter | Type | Description |
|---|---|---|
x | array_like or scalar | Input array or scalar whose positive values are returned. |
out | ndarray, None, or tuple of ndarray and None, optional | Optional output array where the result is stored. If None, a new array is created. |
where | array_like, optional | Boolean mask specifying which elements to compute. Elements where where=False retain their original value. |
casting | str, optional | Defines the casting behavior when computing the function. |
order | str, optional | Memory layout order of the output array. |
dtype | data-type, optional | Defines the data type of the output array. |
subok | bool, optional | Determines 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
