Q:

Write a NumPy program to calculate exp(x) - 1 for all elements in a given array

0

Write a NumPy program to calculate exp(x) - 1 for all elements in a given array

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
x = np.array([1., 2., 3., 4.], np.float32)
print("Original array: ")
print(x)
print("\nexp(x)-1 for all elements of the said array:")
r1 = np.expm1(x)
r2 = np.exp(x) - 1.
assert np.allclose(r1, r2)
print(r1)

Sample Output:

Original array: 
[1. 2. 3. 4.]

exp(x)-1 for all elements of the said array:
[ 1.7182817  6.389056  19.085537  53.59815  ]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now