numpy add 1

numpy add

>>> np.add(1.0, 4.0)
5.0
>>> x1 = np.arange(9.0).reshape((3, 3))
>>> x2 = np.arange(3.0)
>>> np.add(x1, x2)
array([[  0.,   2.,   4.],
       [  3.,   5.,   7.],
       [  6.,   8.,  10.]])

Here is what the above code is Doing:
1. np.add(1.0, 4.0) is adding 1.0 and 4.0
2. np.arange(9.0) is creating an array of 9 elements, starting from 0
3. reshape((3, 3)) is reshaping the array into a 3×3 matrix
4. np.arange(3.0) is creating an array of 3 elements, starting from 0
5. np.add(x1, x2) is adding the two arrays

Similar Posts