VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-compute-numerical-negative-value-for-all-elements-in-a-given-numpy-array/

⇱ How to compute numerical negative value for all elements in a given NumPy array? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to compute numerical negative value for all elements in a given NumPy array?

Last Updated : 15 Jul, 2025

In this article, we will see how to compute the negative value for all elements in a given NumPy array. So, The negative value is actually the number which when added to any number becomes 0. 

Example: 

If we take a number as 4 then -4 is its negative number because when we add -4 to 4 we get sum as 0. Now let us take another example, Suppose we take a number -6 Now when we add +6 to it then the sum becomes zero. hence +6 is the negative value of -6. Now suppose we have an array of numbers: 
 

A = [1,2,3,-1,-2,-3,0]
So, the negative value of A is 
A'=[-1,-2,-3,1,2,3,0].

So, for finding the numerical negative value of an element we have to use numpy.negative() function of NumPy library.

Syntax: numpy.negative(arr, /, out=None, *, where=True, casting=’same_kind’, order=’K’, dtype=None, subok=True[, signature, extobj], ufunc ‘negative’)

Return: [ndarray or scalar] Returned array or scalar = -(input arr or scalar )

Now, let's see the examples:

Example 1:

 Output:

Printing the Original array: [-1 -2 -3 1 2 3 0] 
Printing the negative value of the given array: [ 1 2 3 -1 -2 -3 0] 
 

Example 2:

 
Output: 

Printing the Original array Content:
[[1 2]
[2 3]]
Printing the negative value of the given array:
[[-1 -2]
[-2 -3]]


 

Comment