[Numpy-discussion] the difference between "+" and np.add?

Chao YUE chaoyuejoy at gmail.com
Thu Nov 22 07:41:34 EST 2012

Dear all,

if I have two ndarray arr1 and arr2 (with the same shape), is there some
difference when I do:

arr = arr1 + arr2


arr = np.add(arr1, arr2),

and then if I have more than 2 arrays: arr1, arr2, arr3, arr4, arr5, then I
cannot use np.add anymore as it only recieves 2 arguments.
then what's the best practice to add these arrays? should I do

arr = arr1 + arr2 + arr3 + arr4 + arr5

or I do

arr = np.sum(np.array([arr1, arr2, arr3, arr4, arr5]), axis=0)?

because I just noticed recently that there are functions like np.add,
np.divide, np.substract... before I am using all like directly arr1/arr2,
rather than np.divide(arr1,arr2).

best regards,


Chao YUE
Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)
Batiment 712 - Pe 119
91191 GIF Sur YVETTE Cedex
Tel: (33) 01 69 08 29 02; Fax:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20121122/e556cce8/attachment.html>

More information about the NumPy-Discussion mailing list