Open In App

numpy.negative() in Python

Last Updated : 28 Nov, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
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
# 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
# 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]]

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy