Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
No results
  • About AskPython
  • Blog
  • Contact Me
  • Free Online Developer Tools Hub
  • Home
  • Meet the Team
  • Privacy Policy
  • Python
  • Python Course for Beginners Online FREE
  • Python Tutorial – Mega Index
  • Terms and Conditions

🚀 Supercharge your YouTube channel's growth with AI.

Try YTGrowAI Free
  • Home
  • Blog
  • About AskPython
  • Python Course
  • Start Here

How to Use Numpy Positive in Python?

  • Arulius SavioArulius Savio
  • January 30, 2023
  • NumPy
How to Use Numpy Positive in Python?

This article would be covering a rather strange function within the numpy library of Python. It is so strange that at prima facie one might even question its very existence.

Enter the numpy.positive( ) function! It returns the element-wise numerical positive for the input array.

Makes sense right? But, here is the catch! It does not convert negative numbers within the input array into positives. Fascinating, ain’t it?  Let us have a closer look at the use case of this function, but before that, there is something that needs to be done. Importing the numpy library. The following code can be used to serve the purpose.

import numpy as np

Thereafter, we shall explore further the positive( ) function through each of the following sections.

  • Syntax of the positive( ) function
  • When to use numpy.positive( )?
  • Using numpy.positive( ) on N-Dimensional Arrays

Syntax of the positive( ) function

Following is the syntax of the positive( ) function which contains both the mandatory and the optional inputs required for its functioning.

numpy.positive(x, out=None, *, where=True, dtype=None)

where,

  • x – Scalar or N-dimensional array for which the numerical positive is to be returned
  • out – an optional construct set to none by default, but could be used to store the results in the desired array which is of the same length as the output
  • * – kwargs or keyword argument which is an optional construct used to pass keyword variable length of argument to a function
  • where – an optional construct which is used to calculate the universal function (ufunc) at the given position when set to True (default setting) or not calculate when set to False
  • dtype – an optional construct used to specify the data type which is being used

When to use numpy.positive( )?

Let us construct an array & put it through this function to see what happens.

ar1 = np.array([[-1, 0, -7, 9],
                [3, -4, 23, -13]])
r1 = np.positive (ar1)
print (r1)

Following are the results for the above code.

Numerical Positives For Ar1
Numerical Positives for ar1

It doesn’t even bother to do anything or so you might think! Let’s have a look at the address where the values of the input array & the result are stored.

ad1 = print (id(ar1))
ad2 = print (id(r1))
Comparing Address For Input Result
Comparing Addresses of Input & Result

It is evident that both the input & result are stored at different locations. ‘So what? I can do the same with a copy( ) function?’ one might ask. But does your copy( ) function do this?

r2 = np.positive (ar1, dtype = float)
Converting Data Type Of The Result
Converting Data Type Of The Result

Yep! The numpy.positive( ) function offers a copy of the original input stored at a different location along with the provisions to modify the data type. It works with all data types except for the Boolean which when used shall result in the following.

UFuncNoLoopError: ufunc 'positive' did not contain a loop with signature matching types

One can run the numerical positive of the input array with the modified data type as required, leaving the original untouched. So now you know when to use the positive( ) function.


Using numpy.positive( ) on N-Dimensional Arrays

In this section, we shall demonstrate the usage of positive( ) function to store the result of an N-dimensional array in another designated array of the same size.

ar1 = np.array([[-1, 0, -7, 9],
                [3, -4, 23, -13]])
r2 = np.zeros((2,4))
print(r2)
np.positive (ar1, out=r2, dtype=float)
print(r2)
Results For Ar1
Results for ar1

Conclusion

Now that we have reached the end of this article, hope it has elaborated on how to use the positive( ) function from the numpy library. Here’s another article that details the usage of logaddexp2( ) function from the numpy library in Python. There are numerous other enjoyable and equally informative articles in AskPython that might be of great help to those who are looking to level up in Python. Audere est faucere!

References

  • Official Documentation
Arulius Savio
Arulius Savio
Articles: 56
How to Use Numpy Logaddexp2 in Python?
Previous Post How to Use Numpy Logaddexp2 in Python?
Next Post Pandas merge_ordered - Perform a merge for ordered data with optional filling/interpolation
Pandas merge_ordered – Perform a merge for ordered data with optional filling/interpolation

Related Posts

np.linalg.eig: Eigenvalues and Eigenvectors

np.linalg.eig: Eigenvalues and Eigenvectors

  • November 30, 2026
np.sin() in NumPy: Radians, Arrays, and Examples

How to Use np.sin() in NumPy

  • November 30, 2026
np.outer(): Outer Product in NumPy

np.outer(): Outer Product in NumPy

  • November 14, 2026

Partner Websites

  • GoLangDocs
  • LinuxForDevices
  • CodeForGeek

Popular Categories

  • Python Programming
  • Python Modules
  • OOPS in Python
  • Python Programming Examples
  • Strings in Python

Hall of Fame

  • Python Programming
  • OOPS in Python
  • Creating Python Modules
  • Args and Kwargs in Python
  • Python Dictionary (Dict) Tutorial
  • Python List – 15 Things You MUST Know
  • Python Set – Things You MUST Know
  • Python String Functions: Methods by Task

Important Links

  • Home
  • Python Course
  • Start Here
  • Blog
  • About AskPython
Latest posts
  • np.linalg.eig: Eigenvalues and Eigenvectors
  • What Does %s Mean in a Python Format String?
  • How to Use np.sin() in NumPy
  • cv2.imread: Load Images with OpenCV
  • pd.read_json: Read JSON Into a DataFrame

Copyright © 2026 - AskPython. All rights reserved.