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 › 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....
Discussions

python - How to convert a string array to float array? - Stack Overflow
I basically first converted a multidimensional array to a string array in order to set the values as my dictionary key, and now I need to convert the string array back to a regular float array. For More on stackoverflow.com
🌐 stackoverflow.com
How to cast binary array to float array?
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 reading up on bytes and struct but still having trouble achieving my objective. More on discuss.python.org
🌐 discuss.python.org
2
0
February 20, 2024
python - Converting numpy string array to float: Bizarre? - Stack Overflow
So, this should be a really straightforward thing but for whatever reason, nothing I'm doing to convert an array of strings to an array of floats is working. I have a two column array, like so: N... More on stackoverflow.com
🌐 stackoverflow.com
python - converting a numpy string array to numpy float array - Stack Overflow
I'm reading a csv file to dict. I want the key to be string, and the value to be an array of a float, like this: "A":array[5.19494526e-02 1.17357977e-01 5.19494526e-02] but I'm getting... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com › r/learnpython › converting str array to float array
r/learnpython on Reddit: Converting str array to float array
April 15, 2021 -

I want to convert a string I have from a txt file into a float. The string looks like:

'[1,2,3,4,5]\n'

I can't use . astype() since it returns the error: ' could not convert string to float'. This is because of the newline command at the end of the string '\n'.

I also can't really use many for loops since I have a huge dataset to do this for (but if its the only way I guess I'll have to).

🌐
TutorialsPoint
tutorialspoint.com › article › python-ways-to-convert-array-of-strings-to-array-of-floats
Python - Ways to convert array of strings to array of floats
March 25, 2026 - import numpy as np # Create array of string numbers string_array = np.array(["1.1", "1.5", "2.7", "8.9"]) print("Initial array:", string_array) # Convert to array of floats using astype float_array = string_array.astype(np.float64) print("Final ...
🌐
Bomberbot
bomberbot.com › python › python-ways-to-convert-array-of-strings-to-array-of-floats-a-comprehensive-guide
Python Ways to Convert Array of Strings to Array of Floats: A Comprehensive Guide - Bomberbot
Let's explore various approaches ... straightforward method to convert an array of strings to floats involves iterating through the array and converting each element using the built-in float() function....
🌐
AskPython
askpython.com › python › string › python-string-float-conversion
Python String to float, float to String - AskPython
February 28, 2020 - Python provides us with the built-in float() method to convert the data type of input from String to float.
🌐
IncludeHelp
includehelp.com › python › how-to-convert-an-array-of-strings-to-an-array-of-floats-in-numpy.aspx
Python - How to convert an array of strings to an array of floats in NumPy?
October 8, 2023 - For this purpose, we will use the astype() method inside which we will pass the np.float as an argument. The astype() method Cast a pandas object to a specified dtype. ... # Import numpy import numpy as np # Creating a numpy array arr = np.array(['1.1', '2.2', '3.3']) # Display original array ...
🌐
Delft Stack
delftstack.com › home › howto › numpy › numpy convert string array to float array
How to Convert String to Float in NumPy | Delft Stack
February 2, 2024 - ['1.000' '1.235' '0.000125' '2' ... refer to its official documentation · asarray() is a NumPy function that converts the input array to a NumPy array of a specified type....
Find elsewhere
🌐
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.
🌐
Stack Overflow
stackoverflow.com › questions › 72694568 › how-to-convert-a-string-array-to-float-array
python - How to convert a string array to float array? - Stack Overflow
And I literally just need it back as a regular array · Copyarray = [[0.25 0.2916666666666667], [0.5833333333333334 0.2916666666666667], [0.5555555555555555 0.3333333333333332]] ... Yet none of them work. They either cannot convert str --> float or they still keep the type as a str. Please help. ... Save this answer. ... Show activity on this post. Use ast.literal_eval to convert str to another data type
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to convert array of strings to array of floats in python
5 Best Ways to Convert Array of Strings to Array of Floats in Python - Be on the Right Side of Change
March 10, 2024 - The code snippet creates a generator expression to iterate over str_array and convert each element to a float. The list() constructor is then used to create a list from this generator expression, resulting in float_array. Method 1: For Loop. Easy to understand. Not as Pythonic or efficient with large data sets.
🌐
Iditect
iditect.com › faq › python › how-to-convert-an-array-of-strings-to-an-array-of-floats-in-numpy.html
How to convert an array of strings to an array of floats in numpy?
To convert an array of strings to an array of floats in NumPy, you can use the numpy.array() constructor while specifying the dtype parameter as float.
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to convert a python string to a float array
5 Best Ways to Convert a Python String to a Float Array - Be on the Right Side of Change
February 19, 2024 - Then, it maps each string to a float using a list comprehension, resulting in the desired float array. This method employs map(), in conjunction with split(), to apply the float() function to each element in the list of strings, converting them ...
🌐
Codemia
codemia.io › home › knowledge hub › how to convert an array of strings to an array of floats in numpy?
How to convert an array of strings to an array of floats in numpy? | Codemia
September 24, 2025 - If every element already contains a valid numeric string, the direct solution is astype(float): ... 1import numpy as np 2 3raw = np.array(["1.5", "2.75", "3.0", "4.125"]) 4values = raw.astype(float) 5 6print(values) 7print(values.dtype) This works because NumPy applies the conversion element by element and produces a new array with a floating-point dtype. In most cases, float becomes float64. If the source is a regular Python list instead of a NumPy array, you can convert during array creation:
🌐
Python.org
discuss.python.org › python help
How to cast binary array to float array? - Python Help - Discussions on Python.org
February 20, 2024 - 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 reading up on bytes and struct but still having trouble achieving my objective.
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.fromstring.html
numpy.fromstring — NumPy v2.2 Manual
A string containing the data. ... The data type of the array; default: float. For binary input data, the data must be in exactly this format.
🌐
Cherry Servers
cherryservers.com › home › blog › python › how to convert string to float in python (6 different ways)
How to Convert String to Float in Python (6 Different Ways) | Cherry Servers
February 10, 2026 - NumPy is particularly useful for handling arrays of values, making it an excellent choice for converting multiple strings to floats in the context of numerical computing. Similar to the float() function, using numpy.float64 to convert a string that does not represent a valid floating-point number will result in a ValueError. This is another simplest way to convert string to float in Python.
🌐
YouTube
youtube.com › watch
How to Convert a String Array to a Float Array in Python - YouTube
Learn how to easily convert a string array into a float array in Python using the ast module. Perfect for data manipulation and processing!---This video is b...
Published: May 17, 2025
Views: 0
🌐
Stack Overflow
stackoverflow.com › questions › 72580392 › converting-a-numpy-string-array-to-numpy-float-array
python - converting a numpy string array to numpy float array - Stack Overflow
I want the key to be string, and the value to be an array of a float, like this: "A":array[5.19494526e-02 1.17357977e-01 5.19494526e-02] ... a=pd.read_csv('Encoded.csv', header=None, index_col=0, squeeze=True).to_dict() encoded={} for key, value in a.items(): x = np.array(value) y = np.asarray(x, dtype=np.float32) encoded[key]=y print(encoded) return encoded · but I'm getting "could not convert string to float", why?