NumPy is a Python library used for scientific computing and working with large arrays and matrices. It provides a wide range of mathematical functions including addition and subtraction of arrays.
Addition in NumPy:
To add two arrays using NumPy, we can use the numpy.add() function. It takes two arrays as inputs and returns a new array with the corresponding elements added together. The arrays should have the same shape.
Here's an example of how to add two arrays using NumPy:
Out put :
Subtraction in NumPy:
To subtract two arrays using NumPy, we can use the `numpy.subtract()` function. It takes two arrays as inputs and returns a new array with the corresponding elements subtracted from each other. The arrays should have the same shape.
Here's an example of how to subtract two arrays using NumPy:
Out put
Note that the add() and subtract() functions can also be used with scalar values. In that case, the scalar value is added or subtracted from each element in the array.
Out put
In the above example, we added 1 to each element of `arr` using `np.add(arr, 1)`, and subtracted 2 from each element of `arr` using `np.subtract(arr, 2)`.
Comments
Post a Comment