numpydecimalprecision# get float64 for numpy calculation

```
def chi2_distance(a,b):
d=1-(np.dot(a,b)/(norm(a,axis=1)*norm(b)))
return d
```

a and b are float32 and have max 8 decimals. but i want the calculation has 16 decimals accuracy.

a.shape is r*n and b shape is (n,)

i did this :

```
def chi2_distance(a,b):
a = a.astype(np.float64)
b = b.astype(np.float64)
d=1-(np.dot(a,b)/(norm(a,axis=1)*norm(b)))
return d
```

now the d.dtype is float64 but i still get 8 decimal accuray in results!!

Solution

@hpaulj answered correctly. Simply when you put for the function output tolist(), it can show 16 decimals which is 64 bit for 64bit computer processors. Weirdly apparently numpy can not show more than 32 bit, but when you convert the numpy to a list it can show 16 decimals instead. The code is below:

```
import numpy as np
from numpy.linalg import norm
def chi2_distance(a,b):
a = a.astype(np.float64)
b = b.astype(np.float64)
d=(1-(np.dot(a,b)/(norm(a,axis=1)*norm(b)))).tolist()
return d
k=np.array([[8.34567,2,4],[10000.99887,6,7]])
kk=np.array([100.3456,200,300])
print(k.shape)
print(kk.shape)
hh=chi2_distance(k,kk)
print(hh)
```

- Custom 2D Convolution not sharpening Image
- Problem of Numpy returning error while appending arrays
- Pandas : compute mean or std (standard deviation) over entire dataframe
- What is dtype('O'), in pandas?
- Fill Numpy array with elements from DataFrame and with condition based on the last element of the array itself
- I wanted to create the array below, but for some reason it gives an error.The array itself was created using numpy
- Optimising array addition (y, x, RGBA)
- How to efficiently concatenate many arange calls in numpy?
- Issue with scipy quad integration in python
- implement an integration math equation using odeint in Python
- Efficiently finding consecutive streaks in a pandas DataFrame column?
- Normal Equation Implementation in Python / Numpy
- Custom transformer for sklearn Pipeline that alters both X and y
- How to write a function that works on both Numpy arrays and Pandas series, returning the same type
- Rewrite for-loop vectorized using Numpy
- Using numpy in AWS Lambda
- How to calculate rolling / moving average using python + NumPy / SciPy?
- AttributeError: 'Timedelta' object has no attribute 'dt'
- I need a highly accurate simultaneous equation solver for Python
- Pandas: change between mean/std and plus/minus notations
- Simple tensorflow/keras model with one hot vector output gives error message
- What does axis = 0 do in Numpy's sum function?
- Speedup DataFrame resampling
- numpy.gradient gives unexpected results
- Loading .txt data into 10x256 3d numpy array
- Replacing values in a numpy array by averaging adjacent values
- NumPy matrix with two entries in the same cell is not working
- How to save and read the EXACT same data with pandas?
- Convert c-order index into f-order index in Python
- Max in a sliding window in NumPy array