When you are doing physics simulations you should definitely use floats for everything. 0 is an integer constant in Python, and thus np.tile creates integer arrays; use 0.0 as the argument to np.tile to do floating point arrays; or preferably use the np.zeros(N) instead:

You can check the datatype of any array variable from its dtype member:

>>> np.tile(0, 10).dtype
dtype('int64')
>>> np.tile(0.0, 10).dtype
dtype('float64')
>>> np.zeros(10)
array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])
>>> np.zeros(10).dtype
dtype('float64')

To get a zeroed array of float32 you'd need to give a float32 as the argument:

>>> np.tile(np.float32(0), 10)
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32)

or, preferably, use zeros with a defined dtype:

>>> np.zeros(10, dtype='float32')
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32)
Answer from Antti Haapala on Stack Overflow
🌐
Python Examples
pythonexamples.org › python-create-a-float-array
Python - Create a Float Array
To create a float array in Python, import array module, call array() method of array module, and pass the type code for float type as first argument and the list of elements for the initial values of array as second argument.
Discussions

[Python] | Working with float array
The key phrase you need to look up is "precision" and you'll find a lot of discussion about how decimal numbers are stored. Basically, an approximation of the number is saved. Floats and doubles refer to two ways of storing numbers (where double means it has twice the precision at the cost of twice the space). More on reddit.com
🌐 r/learnprogramming
6
1
September 29, 2021
How to cast binary array to float array?
Hi! I am trying to read some data coming over serial com port. The data comes as a raw binary float array. Python’ serial module reads the data as string. Now, I need to convert this string to float array. I had been rea… More on discuss.python.org
🌐 discuss.python.org
2
0
February 20, 2024
python - How to create a numpy array with float values - Stack Overflow
@user2357112supportsMonica sorry not have python3 installed. Point accepted. 2019-11-21T06:11:27.16Z+00:00 ... Thanks. So np.empty creates a 2 x 2 array where each element is a float? 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
🌐
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-7.php
NumPy: Array converted to a float type - w3resource
August 29, 2025 - Write a NumPy program to convert an array to a floating type. ... # Importing the NumPy library with an alias 'np' import numpy as np # Defining a Python list 'a' containing integers a = [1, 2, 3, 4] # Printing the original array 'a' print("Original array") print(a) # Converting the array 'a' to a NumPy array of type float using asfarray() x = np.asfarray(a) # Printing the array 'x' after converting to a float type print("Array converted to a float type:") print(x)
🌐
GeeksforGeeks
geeksforgeeks.org › python › using-numpy-to-convert-array-elements-to-float-type
Using NumPy to Convert Array Elements to Float Type - GeeksforGeeks
July 15, 2025 - Explanation: Here, an integer array a is converted to a float array res using np.float64(), which casts the elements to 64-bit floating-point numbers efficiently.
🌐
Reddit
reddit.com › r/learnprogramming › [python] | working with float array
r/learnprogramming on Reddit: [Python] | Working with float array
September 29, 2021 -

Someone tell me wtf is going on with my output :(

Why doesn't it just show 1.1 in the array

What is the difference between float and double in simplest terms possible. Can you give an example to distinguish between them?

import array

a1 = array.array('f', [1.1])
a2 = array.array('d', [1.1])
print(a1)
print(a2)

Output:

array('f', [1.100000023841858])
array('d', [1.1])
🌐
Esri Community
community.esri.com › t5 › python-questions › how-do-i-create-a-list-of-floats-in-python › td-p › 516938
How do I create a list of floats in Python? - Esri Community
December 11, 2021 - The code as written is creating a list with a single item, the item being a string with a single character, 'f'. You can initialize a float array, but the syntax is different: >>> import array >>> approxTen = array.array('f') >>> approxTen array('f') >>> ‍‍‍‍‍ · Lists are more common in Python than arrays because of their flexibility with data types and syntactic sugar for working with them, like list comprehensions.
🌐
Python.org
discuss.python.org › python help
How to cast binary array to float array? - Python Help - Discussions on Python.org
February 20, 2024 - Hi! I am trying to read some data coming over serial com port. The data comes as a raw binary float array. Python’ serial module reads the data as string. Now, I need to convert this string to float array. I had been rea…
Find elsewhere
🌐
Pp4rs
pp4rs.github.io › pp4rs-python › notebooks › numpy › 01-create_array.html
Numpy Basics - Creating Arrays — Python for Economics and Business Research
Since Python 3.3, Python has a built in array module that allows us to create a dense array where all elements are of a uniform type: import array number_list = list(range(10)) my_array = array.array('i', number_list) my_array ... Note that i indicates that the contents of my_array are integers, whilst f indicates the contents of another_array are floating point numbers.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-ways-to-convert-array-of-strings-to-array-of-floats
Python | Ways to convert array of strings to array of floats - GeeksforGeeks
July 11, 2025 - Here is the approach to convert ... functions. Create an empty array to store the converted floats. Loop through each element of the input array and convert the current element to a float using the float() function....
🌐
Seaborn Line Plots
marsja.se › home › programming › python › how to convert a float array to an integer array in python with numpy
How to Convert a Float Array to an Integer Array in Python with NumPy
August 20, 2023 - In this post, you will learn how to convert a float array to an integer array in Python using NumPy and the astype() method.
🌐
NumPy
numpy.org › doc › stable › user › basics.types.html
Data types — NumPy v2.4 Manual
There are some exceptions, such ... scalar. Generally, problems are easily fixed by explicitly converting array scalars to Python scalars, using the corresponding Python type function (e.g., int, float, complex, str)....
🌐
FutureLearn
futurelearn.com › home › blog
Creating and accessing NumPy arrays
October 25, 2022 - If the list would have contained one floating point number (e.g. [1, 2, 3.1, 4]) then the array created would have used floating point type for all elements. The first argument of array() is the data for the array. It can be a single list (or tuple), or a nested list of uniformly sized lists that mimics a multi-dimensional array. The second argument of array() is the datatype to be used for the array. It can be one of the basic datatypes in Python (int, float etc.) or it can be one of the more precise datatypes used internally by NumPy (numpy.int8, numpy.float128 etc.).
🌐
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 convert a NumPy array of floating values to a numpy array of integer values. Pictorial Presentation: Sample Solution: Python Code: # Importing the NumPy library and aliasing it as 'np' import numpy as np # Creating a 2-dimensional array 'x' with floating-point values x = np.array([[12.0, 12.51], [2.34, 7.98], [25.23, 36.50]]) # Printing a message indicating the original array elements will be shown print("Original array elements:") # Printing the original array 'x' with its elements print(x) # Printing a message indicating the conversion of float values to integer values print("Convert float values to integer values:") # Converting the floating-point values in the array 'x' to integer values using astype(int) # Printing the array obtained after conversion print(x.astype(int)) Sample Output: Original array elements: [[ 12.
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.arrays.FloatingArray.html
pandas.arrays.FloatingArray — pandas 3.0.1 documentation
To construct a FloatingArray from generic array-like input, use pandas.array() with one of the float dtypes (see examples).
🌐
Finxter
blog.finxter.com › 5-best-ways-to-convert-a-python-float-to-array
5 Best Ways to Convert a Python Float to Array – Be on the Right Side of Change
Printing the array shows the float contained within an array structure. Creating a list in Python is a straightforward approach to convert a float into an array-like structure.
🌐
Quora
quora.com › How-do-you-find-the-float-of-each-element-in-a-matrix-Python-Python-arrays-numpy-development
How to find the float of each element in a matrix Python (Python, arrays, numpy, development) - Quora
Answer: The simplest is to use Numpy’s array method with the dtype=float option. For instance (using an array for simplicity): [code]import numpy as np a = [1, 2.3, “45”] na = np.array(a, dtype=float) print(na) [/code]will print > [ 1. 2.3 45. ] Note that [code ]np.array[/code] is not applying...
🌐
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 and after convert them to integer using the numpy function around ·
🌐
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.
🌐
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 ...