numpy.astype returns a copy of the array. It does not manipulate your array in-place. So you have to assign the value to a variable:

Y = Y.astype(int)
Answer from Joe on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-convert-numpy-array-of-floats-into-integers
How to Convert NumPy Array of Floats into Integers - GeeksforGeeks
July 23, 2025 - Our task is to convert all float-type values of Numpy array to their nearest array of integer values.
Discussions

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
python 3.x - How to convert a numpy integer array to an integer - Stack Overflow
To dig even deeper one must figure ... types of python's ints. ... Sign up to request clarification or add additional context in comments. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Why are p-type MOSFETs used for high-side switching while n-type are used for low side? TO-220 package seems backwards ยท Valid `ccnew` and `ccold` indexes left over after `REINDEX CONCURRENTLY` ... A simple class that takes in a byte array, computes ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Convert Numpy array with 'n' and 'y' into integer array of 0 and 1 - Data Science Stack Exchange
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I have a NumPy array of strings: 'n', 'y', wanna convert it into integer array of 0, 1, how to convert it? More on datascience.stackexchange.com
๐ŸŒ datascience.stackexchange.com
January 10, 2020
How to create an integer array in Python? - Stack Overflow
Explore Stack Internal ... It should not be so hard. I mean in C, ... is all you need. How to create an array of all zeros for a random size. I know the zeros() function in NumPy but there must be an easy way built-in, not another module. ... Python doesn't have a built-in array data structure. More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
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 - >>> 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 and after convert them to integer using the numpy function around
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-convert-data-types-of-arrays-using-numpy-in-python
How to convert data types of arrays using NumPy in Python
Line 7: We use the astype() method to change the my_array array from a float type to an integer type and assign the value to a new variable called new_array.
๐ŸŒ
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 - Numpy provides several functions to convert the data types of numbers. The astype() function is one of the most commonly used functions for this purpose. Letโ€™s dive into how you can use this function to convert Numpy array values into integers.
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-10876.html
Convert element of list to integer(Two dimentional array)
I'm trying to learn arrays(with numpy) in python3 but i am not able to figure out how do i convert the elements of list to integer(in my case i have two dimentional array). I've tried two solutions that i found(its mentioned in the code) but it gives...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-convert-number-to-list-of-integers
Python - Convert Number to List of Integers - GeeksforGeeks
Combination of str() and map() is a straightforward and efficient way to convert a number into a list of integers.
Published ย  July 11, 2025
๐ŸŒ
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)
๐ŸŒ
Finxter
blog.finxter.com โ€บ 5-best-ways-to-convert-an-integer-to-an-array-in-python
5 Best Ways to Convert an Integer to an Array in Python โ€“ Be on the Right Side of Change
February 18, 2024 - This compact line converts the integer to a string, creates a list of characters, casts the list to a NumPy array, and finally uses astype(np.int) to convert the elements to integers. Method 1: Map Function. Efficient. Reduced code readability for beginners. Method 2: List Comprehension. Pythonic ...
๐ŸŒ
Java2Blog
java2blog.com โ€บ home โ€บ python โ€บ convert string array to int array in python
Convert String Array to Int Array in Python [3 ways] - Java2Blog
December 25, 2022 - Use the for loop to loop through the array. Use the int() function to convert each element to an integer in every iteration.
๐ŸŒ
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.
๐ŸŒ
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 - Learn how to convert a 2D float NumPy array into a 2D integer NumPy array in Python. This guide covers various methods, including astype, floor, ceil, and round, with clear code examples and detailed explanations. Enhance your data manipulation skills and streamline your workflows with effective float-to-int conversions in NumPy.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.ndarray.astype.html
numpy.ndarray.astype โ€” NumPy v2.4 Manual
June 22, 2021 - Unless copy is False and the other conditions for returning the input array are satisfied (see description for copy input parameter), arr_t is a new array of the same shape as the input array, with dtype, order given by dtype, order. ... When casting from complex to float or int.
๐ŸŒ
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...