work around tutorial on addition and subtraction on same shape data by NumPy , python in windows 11 or windows 10 or ubuntu or fedora
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 Method in NumPy:
NumPy provides the `numpy.add()` method to perform element-wise addition of two arrays or scalars. Here's an example:
In the above example, we first added two arrays of the same shape `a` and `b` using the `numpy.add()` method and stored the result in c. We then added a scalar value of 10 to the array a using the same method and stored the result in d. Finally, we tried to add two arrays of different shapes e and f, which resulted in a `ValueError` as the shapes were not compatible.
Subtraction Method in NumPy:
NumPy provides the `numpy.subtract()` method to perform element-wise subtraction of two arrays or scalars. Here's an example:
In the above example, we first subtracted two arrays of the same shape `a` and `b` using the `numpy.subtract()` method and stored the result in `c`. We then subtracted a scalar value of 10 from the array `a` using the same method and stored the result in `d`. Finally, we tried to subtract two arrays of different shapes `e` and `f`, which resulted in a `ValueError` as the shapes were not compatible.
Comments
Post a Comment