Use .astype.

>>> a = numpy.array([1, 2, 3, 4], dtype=numpy.float64)
>>> a
array([ 1.,  2.,  3.,  4.])
>>> a.astype(numpy.int64)
array([1, 2, 3, 4])

See the documentation for more options.

Answer from kennytm on Stack Overflow
Discussions

Python: Convert float to int in numpy array
Iโ€™m trying to convert floats to integer in python and store the integer in a string, but Iโ€™m still getting the string with float values. Can anyone please help me to understand, how I can convert float to int and store the int value in the string? Code having issue: _number_of_alphabets, ... More on discuss.python.org
๐ŸŒ discuss.python.org
1
0
February 16, 2022
python - Convert 2D float array to 2D int array in NumPy - Stack Overflow
How do I convert a float NumPy array into an int NumPy array? More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to convert a float array into integer array? - Python - Data Science Dojo Discussions
Iโ€™m converting my float array into an integer array. The code that I wrote contained some errors and didnโ€™t provide the correct output. Can you provide me with any alternative methods of doing the same? or provide me witโ€ฆ More on discuss.datasciencedojo.com
๐ŸŒ discuss.datasciencedojo.com
2
0
March 1, 2023
value error: Failed to convert a Numpy array to a tensor(Unsupported object type Int)
To get more effective help, you need to paste test as text, not a picture of the text. And you should be asking the question in a more appropriate forum (tensorflow in this case). Otherwise you'll be treated like a lazy newb, and will get less help. More on reddit.com
๐ŸŒ r/computervision
4
0
July 13, 2024
๐ŸŒ
Statology
statology.org โ€บ home โ€บ how to convert numpy array of floats into integers
How to Convert NumPy Array of Floats into Integers
April 3, 2025 - Method 2: Convert Floats to Integers (Rounded to Nearest Integer) rounded_integer_array = (np.rint(some_floats)).astype(int) ... The following examples show how to use each method in practice with the following NumPy array of floats:
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Python: Convert float to int in numpy array - Python Help - Discussions on Python.org
February 16, 2022 - Iโ€™m trying to convert floats to integer in python and store the integer in a string, but Iโ€™m still getting the string with float values. Can anyone please help me to understand, how I can convert float to int and store the int value in the string? Code having issue: _number_of_alphabets, _number_of_numbers, _number_of_special_characters = ranges(_size,_number_of_alphabets,_number_of_numbers,_number_of_special_characters) _list = alphabets(_number_of_alphabets) _list = append(_lis...
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ numpy โ€บ python-numpy-exercise-82.php
NumPy: Convert a NumPy array of float values to a NumPy array of integer values - w3resource
August 29, 2025 - print(x.astype(int)): Convert the elements of the array x to integers using the astype method, and then print the resulting array. The astype method creates a new array with the int data type.
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ converting-numpy-array-values-into-integers-a-comprehensive-guide
Converting Numpy Array Values into Integers: A Guide | Saturn Cloud Blog
May 1, 2026 - The astype(int) function converts the floating-point numbers in the array to integers. Note that this function truncates the decimal part of the number, rather than rounding to the nearest integer.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ numpy โ€บ numpy float to int
How to Convert Float Array to Int Array in NumPy | Delft Stack
March 11, 2025 - The astype(int) function converts each float in the array to its corresponding integer value. It effectively truncates the decimal part, which is important to note. In the example above, 1.2 becomes 1, 2.5 becomes 2, and so forth.
Find elsewhere
๐ŸŒ
Pythoneo
pythoneo.com โ€บ how-to-convert-array-from-float-to-int-in-numpy
How to convert array from float to int in Numpy? - Pythoneo: Python Programming, Seaborn & Plotly Tutorials
November 17, 2025 - To convert data type from float to int you need to use astype Numpy function and set โ€˜intโ€™ as a function parameter.
๐ŸŒ
Moonbooks
moonbooks.org โ€บ Articles โ€บ How-to-convert-a-float-array-to-an-integer-array-in-python-
How to convert a float array to an integer array in python ?
August 24, 2022 - >>> import numpy as np >>> A = np.array((0.4, 1.6, 2.1, -3.7, 2.9)) >>> A array([ 0.4, 1.6, 2.1, -3.7, 2.9]) >>> A = np.rint(A) >>> A array([ 0., 2., 2., -4., 3.]) >>> A = A.astype(int) >>> A array([ 0, 2, 2, -4, 3])
๐ŸŒ
Arab Psychology
scales.arabpsychology.com โ€บ home โ€บ how to convert numpy array of floats into integers?
How To Convert NumPy Array Of Floats Into Integers?
November 24, 2025 - To convert a NumPy array of floats into integers, use the numpy.ndarray.astype() method, passing in 'int' as the data type. This will convert each float value
๐ŸŒ
Appdividend
appdividend.com โ€บ how-to-convert-numpy-float-to-int-array-in-python
How to Convert NumPy Array of Floats to an Array of Integers
September 7, 2025 - Then, we can convert that array of floating-point values to integer values using the .astype() method. import numpy as np float_array = np.array([3.14, 2.71, 1.62]) print(float_array.dtype) # Output: float64 rounded_up_integer_array = ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ convert-2d-float-array-to-2d-int-array-in-numpy
Convert 2D float array to 2D int array in NumPy - GeeksforGeeks
July 23, 2025 - When we initialize an array with float elements, its dtype (data-type) is np.float64. To convert the data-type of the array to int, we can change the dtype to np.int32. ... import numpy as np # creating 2D float array.
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ 5 best ways to convert numpy arrays to integers in python
5 Best Ways to Convert numpy Arrays to Integers in Python - Be on the Right Side of Change
February 20, 2024 - The astype() function is used to cast a numpy array to a different type. It provides a way to convert float arrays into integer arrays by specifying the desired output data type as an argument.
๐ŸŒ
Data Science Dojo
discuss.datasciencedojo.com โ€บ python
How to convert a float array into integer array? - Python - Data Science Dojo Discussions
March 1, 2023 - To fix this, you can create a list of numbers and pass it to the np.array() function to convert it into an array. Then, you can use the astype() method to change the data type of the array. Here is the corrected code: This code creates an array of float32 datatype and converts it to int32 using astype(), I hope it helps!
๐ŸŒ
Tutorial Reference
tutorialreference.com โ€บ home โ€บ python โ€บ examples โ€บ faq โ€บ python numpy: how to convert a numpy float array to integer in python
Python NumPy: How to Convert a NumPy Float Array to Integer in Python | Tutorial Reference
import numpy as np values = np.array([0.0, 0.3, 0.7, 1.2, 1.8, 2.5]) bins = np.floor(values).astype(int) print(bins) # [0 0 0 1 1 2] Large floats may overflow when converted to smaller integer types: