I have one-dimensional numpy.ndarray
called y
that contains natural logarithm values. I want to convert all these values into a linear scale and round, using just a single line of code. The following code works, but it provides incorrect results. For example, the first value in result
is 0, instead of 15.
result = [round(np.expm1(x)) for x in range(len(y))]
Use
result = [round(np.expm1(x)) for x in y]
or
result = [round(np.expm1(y[x])) for x in range(len(y))]
The way you have it now, you are putting the array index into the function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.