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
Discussions

python - converting the values in my array into INT - Stack Overflow
I have as array Y =[[ 5. 0. 4. 1. 9. 2. 1. 3. 1. 4. 3. 5. 3. 6. 1. 7. 2. 8. 6. 9. 4. 0. 9. 1. 1. 2. 4. 3. 2. 7. 3. 8. 6. 9. 0. 5. 6. 0. 7. 6. 1. 8. 7.... 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
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
๐ŸŒ
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
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
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...
๐ŸŒ
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.
Top answer
1 of 5
4
In [8]: import numpy as np

In [9]: a = np.array([1,2,3,4,5])

In [10]: int("".join(map(str, a)))
Out[10]: 12345
2 of 5
3

Just use the sum() function with a generator:

>>> sum(e * 10 ** i for i, e in enumerate(x[::-1]))
12345

or, alternatively:

>>> sum(e * 10 ** (len(x) - i-1) for i, e in enumerate(x))
12345

or you could use str.join, again with a generator:

>>> int(''.join(str(i) for i in x))
12345

why?

In the first example, we use a generator to yield each number multiplied by 10 to the power of its position in the array, we then add these together to get our final result. This may be easier to see if we use a list-comprehension, rather than a generator to see what is going on:

>>> [e * 10 ** i for i, e in enumerate(x[::-1])]
[5, 40, 300, 2000, 10000]

and then it is clear from here that, through summing these numbers together, we will get the result of 12345. Note, however, that we had to reverse x before using this, as otherwise the numbers would be multiplied by the wrong powers of 10 (i.e. the first number would be multiplied by 1 rather than 10000).

In the second snippet, the code simply uses a different method to get the right power of 10 for each index. Rather than reversing the array, we simply subtract the index from the length of x (len(x)), and minus one more so that the first element is 10000, not 100000. This is simply an alternative.

Finally, the last method should be fairly self-explanatory. We are merely joining together the stringified versions of each number in the array, and then converting back to an int to get our result.

๐ŸŒ
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.