Well, if you're reading the data in as a list, just do np.array(map(float, list_of_strings)) (or equivalently, use a list comprehension). (In Python 3, you'll need to call list on the map return value if you use map, since map returns an iterator now.)

However, if it's already a numpy array of strings, there's a better way. Use astype().

import numpy as np
x = np.array(['1.1', '2.2', '3.3'])
y = x.astype(np.float)
Answer from Joe Kington on Stack Overflow
🌐
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, a string array a is converted to a float array res using astype(float), creating a new array without modifying the original.
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 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
How to mix strings and floats in a NumPy array?

I'd consider a pandas DataFrame instead - the actual data is stored as a numpy array and so supports everything it needs to, and the headers are separate so you don't need to do awkward slicing when working on the whole data set. You can also then index rows and columns by their index. And it supports going to and from CSVs easily.

As an aside, the way to get arrays to accept mixed types is

np.array([1, 'a'], dtype=object)

but obviously you lose practically all of the benefits of using numpy in the first place.

More on reddit.com
🌐 r/learnpython
8
6
January 25, 2015
Saving a numpy array exactly as is to an image

Why are you doing image processing without image processing libraries? Causing yourself some unneeded pain! Just use scikit-image or opencv! I'm normally not one to suggest using huge libraries for a simple purpose when others would work but...seems silly not to in this example.

With that said, PIL should work fine for this task. Works for me:

In [1]: from PIL import Image

In [2]: import numpy as np

In [3]: img = np.uint8(12 * np.random.rand(50, 50))

In [4]: I = Image.fromarray(img)

In [5]: I.save('asdf.png')

In [6]: I2 = Image.open('asdf.png')

In [7]: img2 = np.array(I2)

In [8]: img
Out[8]:
array([[ 8, 11,  2, ...,  4,  2,  6],
       [ 1,  3,  8, ...,  0,  1, 11],
       [ 2,  2,  0, ..., 11,  4,  6],
       ...,
       [ 7,  5,  9, ..., 11, 11, 10],
       [ 9,  5,  7, ...,  9,  7, 10],
       [ 2,  9, 10, ..., 11,  3, 10]], dtype=uint8)

In [9]: img2
Out[9]:
array([[ 8, 11,  2, ...,  4,  2,  6],
       [ 1,  3,  8, ...,  0,  1, 11],
       [ 2,  2,  0, ..., 11,  4,  6],
       ...,
       [ 7,  5,  9, ..., 11, 11, 10],
       [ 9,  5,  7, ...,  9,  7, 10],
       [ 2,  9, 10, ..., 11,  3, 10]], dtype=uint8)

In [10]: (img == img2).all()
Out[10]: True

My guess is that your image data type is floating point. Generally floating point images are in [0, 1] but it's not a strictly enforced thing--sometimes people keep the values [0, 255] for example, but want more precision. Sometimes the values are [-1, 1]. Etc. Anyways, the point is it isn't entirely consistent. Because of that almost all libraries will scale floating point images automatically. Solution in that case is to convert your images from floating point to uint8.

More on reddit.com
🌐 r/learnpython
6
1
August 30, 2019
🌐
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…
🌐
Vultr Docs
docs.vultr.com › python › third-party › numpy › array › astype
Python Numpy array astype() - Convert Data Type | Vultr Docs
November 8, 2024 - Use the astype() method to convert the array to another data type. ... import numpy as np original_array = np.array([1, 2, 3, 4]) converted_array = original_array.astype(float) print(converted_array) Explain Code
🌐
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])
🌐
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 › 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 ... 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....
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.
🌐
W3Schools
w3schools.com › python › numpy › numpy_data_types.asp
NumPy Data Types
The astype() function creates a copy of the array, and allows you to specify the data type as a parameter. The data type can be specified using a string, like 'f' for float, 'i' for integer etc.
🌐
Hostman
hostman.com › tutorials › how to create an array in python
How to create an array in Python: A Step-by-Step Guide | Hostman
December 23, 2025 - So, let's focus on int and float values. So, the array function makes arrays available in a Python program. While it can be called using different methods, this one seems the most convenient, as it minimizes the number of subsequent errors: ... Of course, this command, like other general instructions, must be indicated in the "header" of the code, that is, at the very top.
Price   $
Address   1999 Harrison St 1800 9079, 94612, Oakland
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.arrays.FloatingArray.html
pandas.arrays.FloatingArray — pandas 3.0.1 documentation
>>> pd.array([0.1, None, 0.3], dtype="Float32") <FloatingArray> [0.1, <NA>, 0.3] Length: 3, dtype: Float32
🌐
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
This code snippet creates an array of type ‘f’ for float and initializes it with a list containing a single float number. 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.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-convert-numpy-array-of-floats-into-integers
How to Convert NumPy Array of Floats into Integers - GeeksforGeeks
April 21, 2025 - Given a numpy array, the task is to filter out integers from an array containing float and integers. Let's see few methods to solve a given task. Method #1 : Using astype(int)Â Python3 # Python code to demonstrate # filtering integers from numpy array # containing integers and float import numpy as
🌐
GeeksforGeeks
geeksforgeeks.org › convert-2d-float-array-to-2d-int-array-in-numpy
Convert 2D float array to 2D int array in NumPy - GeeksforGeeks
October 2, 2023 - We can convert the 2D int array to 2D float array in the same manner. ... Here we will learn how to convert 1D NumPy to 2D NumPy Using two methods. Numpy is a Python package that consists of multidimensional array objects and a collection of operations or routines to perform various operations ...
🌐
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 - An array is a common structure that stores multiple items of a similar type together in a single place in a contiguous memory location. We can create arrays of any one of the data types provided in Python. In Python, the float values represent all the numbers containing a decimal point.
🌐
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.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-convert-numpy-int-to-float-with-a-separate-numpy-array-a-comprehensive-guide-for-data-scientists
How to Convert Numpy Int to Float with a Separate Numpy Array: A Guide for Data Scientists | Saturn Cloud Blog
October 4, 2023 - This function creates a copy of the array, and converts the data type. ⚠ This code is experimental content and was generated by AI. Please refer to this code as experimental only since we cannot currently guarantee its validity · float_array = int_array.astype('float') print(float_array)