Use the astype method.

>>> x = np.array([[1.0, 2.3], [1.3, 2.9]])
>>> x
array([[ 1. ,  2.3],
       [ 1.3,  2.9]])
>>> x.astype(int)
array([[1, 2],
       [1, 2]])
Answer from BrenBarn on Stack Overflow
๐ŸŒ
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...
๐ŸŒ
Moonbooks
en.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 ?
March 22, 2019 - To convert a float array to an integer array in python, a solution is to use astype, example: >>> 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 = A.astype(int) >>> A array([ 0, 1, 2, -3, 2]) It is also possible to round the numbers ...
๐ŸŒ
Data Science Dojo
discuss.datasciencedojo.com โ€บ python
How to convert a float array into integer array? - Python - Data Science Dojo Discussions
March 1, 2023 - 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 with the errors my code contains? import numpy as np x=np.random.randn() x = x.astype('int64') print(x.dtype) print(x) AttributeError: 'float' object has no attribute 'astype' In the code, Iโ€™m creating a random array and converting its dtype into int64.
๐ŸŒ
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 - Write a NumPy program to cast an array of floats to integers using astype and verify that the values are truncated. Create a function that converts a float array to an integer array and then performs arithmetic to confirm type conversion.
๐ŸŒ
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 - Another approach to converting float arrays to integers involves using the numpy.floor() function. This function rounds each element down to the nearest integer.
Find elsewhere
๐ŸŒ
CodeSpeedy
codespeedy.com โ€บ home โ€บ how to convert a float array to int in python โ€“ numpy
Convert float array to int in Python in different ways - CodeSpeedy
October 9, 2023 - import numpy as np codespeedy_float_list = [45.45,84.75,69.12] codespeedy_array = np.array(codespeedy_float_list) print(np.int_(codespeedy_array))
๐ŸŒ
Replit
replit.com โ€บ home โ€บ discover โ€บ how to convert a float to an int in python
How to convert a float to an int in Python
February 6, 2026 - import numpy as np float_array ... each float, you can convert an entire array to integers in one shot using the .astype() method....
๐ŸŒ
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 1: Convert Floats to Integers (Rounded Down) rounded_down_integer_array = float_array.astype(int)
๐ŸŒ
Medium
medium.com โ€บ @amit25173 โ€บ different-ways-to-convert-numpy-float-to-int-f47f3be42453
Different Ways to Convert NumPy Float to Int | by Amit Yadav | Medium
April 12, 2025 - import numpy as np float_list = [1.9, 2.8, 3.7, 4.5] float_array = np.array(float_list) # Convert list to NumPy array int_array = float_array.astype(int) # Convert to integers print(int_array) # Output: [1 2 3 4] ... Absolutely! NumPy operations are vectorized, meaning they execute much faster than regular Python loops.
๐ŸŒ
Java2Blog
java2blog.com โ€บ home โ€บ python โ€บ python array โ€บ convert float array to int array in python
Convert float array to int array in Python - Java2Blog
November 11, 2021 - It is an optional parameter and is inferred by the function by looking at the input data. We can explicitly specify it as int to convert the float values to an integer by removing the value after the decimal point.
๐ŸŒ
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. See also Overcoming MemoryError in NumPy: Efficient Handling of Large Arrays
๐ŸŒ
Python Guides
pythonguides.com โ€บ convert-float-to-int-python
How To Convert Float To Int In Python?
March 21, 2025 - The most simple way to convert a float to an integer in Python is by using the built-in int() function.
๐ŸŒ
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 - Type-casting the array directly to the np.int32 data-type. To convert 2D float array to int array, we can make use of the astype() method.
๐ŸŒ
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
December 2, 2023 - Original Array: [1.23 4.56 7.89] Converted Array: [1 4 7] The astype(int) function converts the floating-point numbers in the array to integers.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-convert-float-to-int-in-python
How to convert Float to Int in Python? - GeeksforGeeks
May 10, 2025 - In Python, a string can be converted into an integer using the following methods : Method 1: Using built-in int() function: If your string contains a decimal integer and you wish to convert it into an int, in that case, pass your string to int() ...