Python Forum

Full Version: System showing np.int64(xxx) as output
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was using Numpy and try to find the number in an array which is the closest to the number 57. I write the following code.
a = np.array([78,22,65,87,12,98,63,79])
x = 57
a[np.argmin(np.abs(a - x))]
The output I get is
Output:
np.int64(63)
instead of 63 only. I am guessing it has to do with some setting in my system. Can you explain how I can get the number only without the data type? Thanks in advance.
it seems correct ...

import numpy as np
a = np.array([78, 22, 65, 87, 12, 98, 63, 79])
x = 57

Index = np.argmin(np.abs(a - x))
minValue = a[Index]
print(f"Index = {Index} & min difference = {minValue}")

r = a[np.argmin(np.abs(a - x))]
print(f"r = {r}")
Output:
Index = 6 & min difference = 63 r = 63
Are you running the code in an anaconda notebook? When I run your code as a program or in the interactive interpreter I don't see the np.int64() part. If you don't like the way the value is displayed, use the print() command.
(Aug-10-2024, 10:20 AM)deanhystad Wrote: [ -> ]Are you running the code in an anaconda notebook? When I run your code as a program or in the interactive interpreter I don't see the np.int64() part. If you don't like the way the value is displayed, use the print() command.

Yes, I am running my code in JupyterLab. Would you mind telling me why the output is different in JupyterLab?