print ndarray float64 as simple integer in python in python

You can use the astype method in NumPy to convert a float64 ndarray to an integer type such as int64. This will essentially truncate the decimal part of the float numbers, turning them into integers.

Here's how you can do it:

main.py
import numpy as np

# Create a float64 ndarray
arr_float64 = np.array([1.5, 2.75, 3.2], dtype=np.float64)

# Convert the float64 ndarray to int64
arr_int64 = arr_float64.astype(np.int64)

print(arr_int64)
205 chars
10 lines

This code will output:

main.py
[1 2 3]
8 chars
2 lines

related categories

gistlibby LogSnag