Saturday, June 13, 2026
HomeLanguagesnumpy.negative() in Python

numpy.negative() in Python

numpy.negative() function is used when we want to compute the negative of array elements. It returns element-wise negative value of an array or negative value of a scalar.

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

Parameters :
arr : [array_like or scalar] Input array.
dtype : The type of the returned array. By default, the dtype of arr is used.
out : [ndarray, optional] 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.
where : [array_like, optional] Values of True indicate to calculate the ufunc at that position, values of False indicate to leave the value in the output alone.
**kwargs : Allows to pass keyword variable length of argument to a function. Used when we want to handle named argument in a function.

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

Code #1 : Working




# Python program explaining
# numpy.negative() function
  
import numpy as geek
in_num = 10
  
print ("Input  number : ", in_num)
    
out_num = geek.negative(in_num) 
print ("negative of input number : ", out_num) 


Output :

Input  number :  10
negative of input number :  -10

 
Code #2 :




# Python program explaining
# numpy.negative function
  
import numpy as geek
  
in_arr = geek.array([[2, -7, 5], [-6, 2, 0]])
   
print ("Input array : ", in_arr) 
    
out_arr = geek.negative(in_arr) 
print ("negative of array elements: ", out_arr) 


Output :

Input array :  [[  2.   2.   2.]
 [  2.   2.  nan]]
product of array elements:  32.0Input array :  [[ 2 -7  5]
 [-6  2  0]]
negative of array elements:  [[-2  7 -5]
 [ 6 -2  0]]
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS