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

NumPy | Python Methods and Functions

With Numpy numpy.ndarray .__ add __ () we can add a specific value that is provided as a parameter in ndarray .__ add __ () . A value will be appended to each item in a NumPy array .

Syntax: ndarray .__ add __ ($ self, value, /)

Return: self + value

Example # 1:
In this example, we see that each the array element is added with the value specified as a parameter in the ndarray .__ add __ () method. Remember one thing, this will not work for double values.

# import important module into python

import numpy as np

 
# make an array with NumPy

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

 
# applying the ndarray method .__ add __ ()

 print (gfg .__ add __ ( 5 ))

Exit:

 [6 7 8 9 10]  

Example # 2:

# import important module into python

import numpy as np

 
# make an array with NumPy

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

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

 
# applying the ndarray method .__ add __ ()

print (gfg .__ add __ ( 5 ))

Output:

 [[6 7 8 9 10] [11 10 9 8 7]] 




Get Solution for free from DataCamp guru