Python | Numpy numpy.ndarray .__ neg __ ()

With the numpy.ndarray .__ neg __ () method Numpy, you can multiply each and every element of an array with -1. Therefore, the resulting array with values ​​such as positive values ​​becomes negative and negative values ​​become positive .

Syntax : ndarray .__ neg __ ($ self, /)

Return: -self

Example # 1:
In this example, we can see that after applying numpy .__ neg __ () we get a simple array with a combination of positive and negative values ​​in the array.

# import important module in python

import numpy as np

 
# make an array with NumPy

gfg = np.array ([ 1 , - 2 , 3 , 4 , 5 , 6 ])

  
# applying the numpy method .__ neg __ ()

print (gfg .__ neg__ ())

Exit:

 [-1 2 -3 -4 -5 -6] 

Example # 2:

# import an important module into python

import numpy as np

  
# make an array with NumPy

gfg = np.array ([[ 1 , 2 , - 3 , 4 , 5 , 6 ],

[ - 6 , 5 , 4 , 3 , 2 , - 1 ]])

 
# application method numpy .__ neg __ ()

print (gfg .__ neg __ ())

Exit:

 [[-1 -2 3 -4 -5 -6] [6 -5 -4 -3 -2 1]]