-1

I want to add a number to a numpy array and I would like to keep all the decimals. How can I do it? This is what I tried so far:

import numpy as np
a = np.array([0.25350021,  0.16900018, -0.16899996])
b = 1.05292844e-07
np.around(a+b,decimals=15)

The output is array([ 0.25350032, 0.16900029, -0.16899985]), but b has non-zero digits up to 10^-15 and I would like them to appear explicitly in the numpy array. Thank you!

JohnDoe122
  • 638
  • 9
  • 23

1 Answers1

1

I don't know why it is not keeping the 15 digits, however, here is a solution that I came up with to get the answer that you want.

import numpy as np

def addNumberToArray(array, number):
    newArray = []
    for element in array:
        element = element + number
        newArray.append(element)
    return newArray


a = np.array([0.25350021,  0.16900018, -0.16899996])
b = 1.05292844e-07
result = addNumberToArray(a, b)
print (result)

Output: [0.253500315292844, 0.169000285292844, -0.168999854707156]