What Python function is used to perform element-wise mathematical operations on Numpy arrays?

describe()
plt.plot()
df.apply()
np.add()

The correct answer is D. np.add().

np.add() is a Python function that is used to perform element-wise mathematical operations on Numpy arrays. It takes two Numpy arrays as input and returns a new Numpy array with the elements of the two input arrays added together.

For example, if you have two Numpy arrays, arr1 and arr2, you can use np.add() to add them together like this:

“`

arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
np.add(arr1, arr2)
array([5, 7, 9])
“`

The np.add() function can also be used to add a scalar value to a Numpy array. For example, if you have a Numpy array arr1 and you want to add the number 5 to each element of the array, you can use np.add(arr1, 5) like this:

“`

arr1 = np.array([1, 2, 3])
np.add(arr1, 5)
array([6, 7, 8])
“`

The np.add() function is a very versatile function that can be used to perform a variety of element-wise mathematical operations on Numpy arrays.

The other options are not correct because they are not used to perform element-wise mathematical operations on Numpy arrays.

  • describe() is a function that is used to get a summary of the statistics of a Numpy array.
  • plt.plot() is a function that is used to plot a Numpy array.
  • df.apply() is a function that is used to apply a function to each row of a DataFrame.
Exit mobile version